What is a Database?
A database is like a digital filing cabinet that stores information in an organized way.
-
Example: An Excel sheet that keeps track of all your customers' names, emails, and orders.
-
But databases are much stronger - they can handle millions of records without slowing down.
Types of Databases
-
Relational Databases (SQL)
-
Stores data in tables (like spreadsheets with rows and columns)
-
Tables are connected to each other (e.g., Customers table ↔ Orders table)
-
Examples: MySQL, PostgreSQL
-
-
NoSQL Databases
-
Stores data in flexible formats (not just tables)
-
Good for huge amounts of unstructured data
-
Examples: MongoDB (stores data like JSON documents)
-
What is SQL?
SQL (Structured Query Language) is the language we use to talk to relational databases.
-
It's like giving commands to your database:
-
"Show me all customers"
-
"Add this new product"
-
"Update this user's address"
-
Basic SQL Rules
-
Statements end with a semicolon (;) : SELECT * FROM customers;
-
SQL is (mostly) case-insensitive :
(But we usually write commands in UPPERCASE for clarity)SELECT=select=SeLeCt -
Use quotes for text
WHERE name = 'John' -- Correct WHERE name = John -- Wrong (will cause error)
Main Types of SQL Commands
| Command Type | Purpose | Examples |
|---|---|---|
| DDL (Data Definition) | Create/change structure | CREATE TABLE, ALTER, DROP |
| DML (Data Manipulation) | Work with data | SELECT, INSERT, UPDATE, DELETE |
| DCL (Data Control) | Security | GRANT, REVOKE |
Simple Example
Imagine a library database:
-- Create a table for books
CREATE TABLE books (
id INT PRIMARY KEY,
title VARCHAR(100),
author VARCHAR(50),
price DECIMAL(5,2)
);
-- Add a book
INSERT INTO books VALUES (1, 'The Alchemist', 'Paulo Coelho', 9.99);
-- Find all books
SELECT * FROM books;
Output:
| id | title | author | price |
|----|----------------|----------------|-------|
| 1 | The Alchemist | Paulo Coelho | 9.99 |
Why Learn SQL?
-
Used by almost every company that stores data
-
Needed for jobs like:
-
Data analysis
-
Web development
-
Business reporting
-
-
Even if you use tools like Excel, SQL helps work with LARGE datasets