SQL COMMANDS

1) DDL (Data Definition Language)
2) DML (Data Manipulation Language)
3) DCL (Data Control Language)
4) TCL (Transaction Control Language)
5) DQL ( Data Query Language)

  1. DDL(Data Definition Language)
    CREATE
    ALTER
    DROP
    TRUNCATE
    DDL changes the structure of the table like
    creating a table, deleting a table, altering a table,
    etc.
    All the command of DDL are auto-committed that
    means it permanently save all the changes in the
    database.
    Here are some commands that come under DDL:

a. CREATE:
This statement is used to create a new table in the
database.
Syntax:
CREATE table table_name
(column_name data type,
column_name data type, …);
b. ALTER:
It is used to alter the structure of the database.
Syntax:
To add a new column in the table:
ALTER TABLE table_name ADD (column_name
COLUMN-definition);
To modify existing column in the table:
ALTER TABLE table_name
MODIFY(column_definitions….);

c. DROP:
It is used to delete both the structure and record
stored in the table.
Syntax:
DROP TABLE table_name;
TRUNCATE TABLE table_name;
d. TRUNCATE:
It is used to delete all the rows from the table and
free the space containing the table.
Syntax:TRUNCATE TABLE table_name;

  1. DML(Data Manipulation Language)
    DML commands are used to modify the database.
    It is responsible for all form of changes in the
    database.
    The command of DML is not auto-committed that
    means it can’t permanently save all the changes
    in the database. They can be rollback.
    INSERT
    UPDATE
    DELETE
    Here are some commands that come under DML:INSERT UPDATE DELETE

a. INSERT:
INSERT INTO table_name
(col1, col2, col3,…. col N)
VALUES (value 1, value 2, value 3, …. value N);
This statement is used to insert data into the row of
a table.
UPDATE table_name SET column1 = value1,
column2 = value2,…
WHERE condition;
b. UPDATE:
This command is used to update or modify the value
of a column in the table.
Syntax:
c. DELETE:
This command is used to remove one or more row
from a table.
Syntax:
DELETE FROM table_name
WHERE some_condition;

  1. DCL(Data Control Language)
    DCL commands are used to grant and take back
    authority from any database user.
    Grant
    Revoke
    Here are some commands that come under DCL:

a. GRANT:
This command gives users access privileges to the
database.
Syntax:
GRANT SELECT, UPDATE ON MY_TABLE TO
SOME_USER, ANOTHER_USER;
b. REVOKE:
This command withdraws the user’s access
privileges given by using the GRANT command.
Syntax:
REVOKE SELECT, UPDATE ON MY_TABLE FROM
USER 1, USER 2;

  1. TCL(Transaction Control Language)
    TCL commands can only use with DML
    commands like INSERT, DELETE and UPDATE
    only.
    These operations are automatically committed in
    the database that’s why they cannot be used
    while creating tables or dropping them.
    COMMIT
    ROLLBACK
    SAVEPOINT
    The commands that come under TCL are:

a. COMMIT:
Commit command is used to save all the transactions
to the database.
Syntax:
COMMIT;
b. ROLLBACK:
Rollback command is used to undo transactions that
have not already been saved to the database.
Syntax:
ROLLBACK;
It is used to roll the transaction back to a certain
point without rolling back the entire transaction.
Syntax:
SAVEPOINT SAVEPOINT_NAME;
c. SAVEPOINT:

  1. DQL(Data Query Language)
    DQL is used to fetch the data from the database.
    It uses only one command:
    SELECT

a. SELECT:
This command is used to retrieve data from the
database
Syntax:
SELECT column 1,column 2 FROM table_name
WHERE condition(s);

kamblenayan826

Leave a Reply

Your email address will not be published. Required fields are marked *