SQL Commands

 

  SQL Commands 



Data Definition Language (DDL)

  1. CREATE – Creates a new table, database, index, or view.

    CREATE TABLE Employees (
        ID INT PRIMARY KEY,
        Name VARCHAR(50),
        Age INT,
        Department VARCHAR(50)
    );
    
  2. ALTER – Modifies an existing database structure.

    ALTER TABLE Employees ADD Salary DECIMAL(10,2);
    
  3. DROP – Deletes a database object (table, database, etc.).

    DROP TABLE Employees;
    
  4. TRUNCATE – Removes all records from a table but keeps its structure.

    TRUNCATE TABLE Employees;
    

Data Manipulation Language (DML)

  • INSERT – Adds new rows to a table.

    INSERT INTO Employees (ID, Name, Age, Department) VALUES (1, 'John Doe', 30, 'HR');
    
  • UPDATE – Modifies existing records.

    UPDATE Employees SET Age = 31 WHERE ID = 1;
    
  • DELETE – Removes records from a table.

    DELETE FROM Employees WHERE ID = 1;
    

Data Query Language (DQL)

  • SELECT – Retrieves data from a database.

    SELECT * FROM Employees;

Data Control Language (DCL)

  • GRANT – Provides access to users.

    GRANT SELECT, INSERT ON Employees TO user_name;
    
  • REVOKE – Removes user access.

    REVOKE INSERT ON Employees FROM user_name;
    

Transaction Control Language (TCL)

  • COMMIT – Saves changes permanently.

    COMMIT;
    
  • ROLLBACK – Reverts uncommitted changes.

    ROLLBACK;
  • SAVEPOINT – Creates a savepoint in a transaction.

           SAVEPOINT Save1;

Comments

Popular Posts