Previous

SQL Fundamentals

Next

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

  1. 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

  2. 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

  1. Statements end with a semicolon (;) : SELECT * FROM customers;

  2. SQL is (mostly) case-insensitive :  SELECT = select = SeLeCt

    (But we usually write commands in UPPERCASE for clarity)
  3. 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 TABLEALTERDROP
DML (Data Manipulation) Work with data SELECTINSERTUPDATEDELETE
DCL (Data Control) Security GRANTREVOKE

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