SQL Introduction

What is SQL?

SQL (Structured Query Language) is a language designed to store, retrieve, manage, and manipulate data in relational databases like MySQL, PostgreSQL, and SQL Server.

Why Use SQL?

  • Universal and widely adopted
  • Efficient at handling large data sets
  • Declarative — you state what you want, not how to get it

SQL is Declarative

SQL queries describe what you want from the database (e.g., all customers older than 30), not the step-by-step computation.

SQL is Standardized

SQL is governed by ANSI/ISO standards, though different systems (like MySQL or SQLite) have slight variations.

SQL Categories

  • DDL (Data Definition Language): Defines the structure of the database. Includes:
    • CREATE: Creates new tables, views, or databases
    • ALTER: Modifies an existing database structure
    • DROP: Deletes tables, views, or databases
  • DML (Data Manipulation Language): Used to interact with and modify the data itself.
    • SELECT: Retrieves data from the database
    • INSERT: Adds new data
    • UPDATE: Modifies existing data
    • DELETE: Removes data
  • DCL (Data Control Language): Manages access and permissions.
    • GRANT: Gives privileges to users
    • REVOKE: Removes privileges
  • TCL (Transaction Control Language): Controls transactions and data integrity.
    • COMMIT: Saves all changes made during the transaction
    • ROLLBACK: Undoes changes since the last COMMIT

Real-World Use Cases

  • Database-backed websites and apps
  • Data analytics and reporting
  • Business Intelligence systems
  • ETL pipelines and backend services

Best Practices

  • Use indentation and line breaks for clarity
  • Add comments for complex logic
  • Familiarize yourself with your SQL dialect

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic