DDL is used for defining and managing the structure of a database, including creating, altering, and deleting database objects such as tables, indexes, and views.
CREATE
Used to create database objects like tables, views, and indexes.
UPDATE employees
SET emp_salary = 55000
WHERE emp_id = 1;
DELETE
Used to remove data from a table.
Example
DELETE FROM employees
WHERE emp_id = 1;
Data Control Language (DCL)
DCL is used for managing the permissions and access control to the database objects, including granting and revoking privileges to users and roles. GRANT: Used to give specific privileges to users or roles.
Example
GRANT SELECT ON employees TO user1;
REVOKE
Used to revoke previously granted privileges from users or roles.
Example
REVOKE SELECT ON employees FROM user1;
Transaction Control Language (TCL)
TCL is used for managing transactions within a database, including controlling their initiation, committing changes, and rolling back in case of errors. COMMIT: Used to save changes made during the current transaction.
Example
COMMIT;
ROLLBACK
Used to undo changes made during the current transaction.
Example
ROLLBACK;
SAVEPOINT
Used to set a point within a transaction to which you can later roll back.
Example
SAVEPOINT my_savepoint;
Data Query Language (DQL)
DQL is used for querying and retrieving data from the database using SQL SELECT statements.
SELECT
Used to retrieve data from one or more tables.
Example
SELECT emp_name, emp_salary
FROM employees
WHERE emp_salary > 50000;