Skip to content

Files

Latest commit

 

History

History
95 lines (62 loc) · 4.5 KB

Commands.md

File metadata and controls

95 lines (62 loc) · 4.5 KB

Commands of SQL

1. Data Definition Language (DDL)

  1. CREATE

     Used to create a table or database

           Syntax:  CREATE DATABASE DatabaseName
           Ex:          CREATE DATABASE School

           Syntax: CREATE TABLE TableName
           Ex:          CREATE TABLE Student

  2. ALTER

    Used to change the structure of the table

    • Add a new column

             Syntax: ALTER TABLE TableName ADD ColumnName datatype(value)
             Ex:          ALTER TABLE Student ADD age NUMBER(2)

    • Remove an existing column

             Syntax: ALTER TABLE TableName DROP COLUMN ColumnName
             Ex:          ALTER TABLE Student DROP COlUMN address

    • Rename the existing column

             Syntax: ALTER TABLE TableName RENAME COLUMN oldColumnName TO newColumnName
             Ex:          ALTER TABLE Student RENAME COLUMN email TO emailid

    • Increase or decrease the column size

             Syntax: ALTER TABLE TableName MODIFY ColumnName datatype(newValue)
             Ex:          ALTER TABLE Student MODIFY emailid VARCHAR(30)

    • Change the column data type

             Syntax: ALTER TABLE TableName MODIFY ColumnName datatype
             Ex:          ALTER TABLE Student MODIFY DateofBirth year

  3. TRUNCATE

    Removes all the rows from the table

           Syntax: TRUNCATE TABLE TableName
           Ex:          TRUNCATE TABLE Student

  4. DROP

    Drops the entire table structure

           Syntax: DROP TABLE TableName
           Ex:          DROP TABLE Student

2. Data Manipulation Language (DML)

  1. INSERT

    Insert rows to tables

           Syntax: INSERT INTO TableName(column1, column2,...) VALUES(value1, value2,...)
           Ex:          INSERT INTO Student(RollNo, Name, Age) VALUES (1, 'Srishti', 21)

  2. UPDATE

    Modify existing rows in a table

           Syntax: UPDATE TableName SET ColumnName = value [WHERE condition]
           Ex:          UPDATE Student SET Age = 22 WHERE RollNo = 1;

  3. SELECT

    Used to retrieve rows from a database or a table

           Syntax: SELECT ColumnName FROM TableName
           Ex:          SELECT Name FROM Student

  4. DELETE

    Remove existing rows from the table

           Syntax: DELETE FROM TableName [WHERE condition]
           Ex:          DELETE FROM Student WHERE RollNo = 3;

3. Data Control Language (DCL)

  1. GRANT

    Gives users access privileges to the database

  2. REVOKE

    Withdraws the user’s access privileges given by using the GRANT command

4. Transaction Control Language (TCL)

  1. COMMIT

    Commits a transaction

  2. ROLLBACK

    Rollbacks a transaction in case of any error occurs

  3. SAVEPOINT

    Sets a savepoint within a transaction