SQL COMMANDS
DDL (Data Definition Language)
DML (Data Manipulation Language)
DCL (Data Control Language)
TCL (Transaction Control Language)
DQL ( Data Query Language)
Created By: Sanya Rastogi
1. DDL(Data Definition Language)
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:
CREATE
ALTER
DROP
TRUNCATE
a. CREATE:
This statement is used to create a new table in the
database.
Syntax:
CREATE table table_name
(column_name datatype,
column_name datatype, ...);
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;
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;
2. 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.
Here are some commands that come under DML:
INSERT
UPDATE
DELETE
a. INSERT:
This statement is used to insert data into the row of
a table.
Syntax:
INSERT INTO table_name
(col1, col2, col3,.... col N)
VALUES (value1, value2, value3, .... valueN);
b. UPDATE:
This command is used to update or modify the value
of a column in the table.
Syntax:
UPDATE table_name SET column1 = value1,
column2 = value2,…
WHERE condition;
c. DELETE:
This command is used to remove one or more row
from a table.
Syntax:
DELETE FROM table_name
WHERE some_condition;
3. DCL(Data Control Language)
DCL commands are used to grant and take back
authority from any database user.
Here are some commands that come under DCL:
Grant
Revoke
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
USER1, USER2;
4. 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.
The commands that come under TCL are:
COMMIT
ROLLBACK
SAVEPOINT
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;
c. SAVEPOINT:
It is used to roll the transaction back to a certain
point without rolling back the entire transaction.
Syntax:
SAVEPOINT SAVEPOINT_NAME;
5. 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 column1,column2 FROM table_name
WHERE condition(s);
Created By: Sanya Rastogi