Skip to content

1. What is SQL

What is SQL?

SQL (Structured Query Language) is a standard language used for managing and manipulating relational databases. It allows users to store, retrieve, update, and delete data, as well as define and control database structures.


What is SQL Used For?

  1. Data Retrieval – Query databases to fetch specific records using SELECT.

    SELECT name, age FROM users WHERE age > 25;
    

  2. Data Insertion – Add new records to a table using INSERT.

    INSERT INTO users (name, age) VALUES ('John Doe', 30);
    

  3. Data Modification – Update existing records using UPDATE.

    UPDATE users SET age = 35 WHERE name = 'John Doe';
    

  4. Data Deletion – Remove records using DELETE.

    DELETE FROM users WHERE age < 18;
    

  5. Schema Definition – Create and modify database structures (CREATE, ALTER, DROP).

    CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(100));
    

  6. Data Security & Access Control – Manage user permissions with GRANT and REVOKE.

    GRANT SELECT ON users TO admin;
    

  7. Transactions & Concurrency Control – Ensure database consistency using transactions (BEGIN, COMMIT, ROLLBACK).

    BEGIN;
    UPDATE accounts SET balance = balance - 100 WHERE id = 1;
    UPDATE accounts SET balance = balance + 100 WHERE id = 2;
    COMMIT;
    


Types of SQL Commands

SQL is categorized into different groups based on its purpose:

  1. Data Definition Language (DDL) – Defines database structure.
  2. CREATE, ALTER, DROP, TRUNCATE

  3. Data Manipulation Language (DML) – Works with data.

  4. SELECT, INSERT, UPDATE, DELETE

  5. Data Control Language (DCL) – Manages user permissions.

  6. GRANT, REVOKE

  7. Transaction Control Language (TCL) – Manages transactions.

  8. COMMIT, ROLLBACK, SAVEPOINT

Why Use SQL?

  • Standardized – Used in almost all relational database systems (MySQL, PostgreSQL, SQL Server, Oracle, SQLite).
  • Efficient – Optimized for handling large amounts of structured data.
  • Scalable – Works for small applications to enterprise-level systems.
  • Essential for Data Management – Used in software development, analytics, business intelligence, and more.