Data Query Language (DQL)
Q: What is DQL in SQL?
● A: DQL stands for Data Query Language. It is used to retrieve data from a database.
The primary DQL command is SELECT, which allows you to fetch data from one or more
tables based on specific conditions. For example, SELECT * FROM table_name;
retrieves all records from a table.
DML (Data Manipulation Language) in SQL is a subset of SQL commands used to manipulate
and manage the data within a database. These commands allow you to retrieve, insert, update,
and delete data in database tables.
INSERT: Adds new records to a table.
Example: INSERT INTO employees (name, age, department) VALUES ('John',
30, 'HR');
UPDATE: Modifies existing data in a table.
Example: UPDATE employees SET age = 31 WHERE name = 'John';
DELETE: Removes records from a table.
Example: DELETE FROM employees WHERE name = 'John';
3. Data Definition Language (DDL)
Q: What is the purpose of DDL commands in SQL?
● A: DDL stands for Data Definition Language, which is used to define and manage
database structures such as tables, views, and indexes. Common DDL commands
include:
○ CREATE: Used to create a new database object, like a table.
Example: CREATE TABLE employees (id INT, name VARCHAR(100),
department VARCHAR(50));
○ ALTER: Modifies an existing database object.
Example: ALTER TABLE employees ADD age INT;
○ DROP: Deletes an object from the database.
Example: DROP TABLE employees;
○ TRUNCATE: Removes all rows from a table, but keeps the structure intact.
Example: TRUNCATE TABLE employees;
4. Data Control Language (DCL)
Q: What is DCL in SQL?
● A: DCL stands for Data Control Language. It is used to manage permissions and access
control to database objects. Common DCL commands include:
○ GRANT: Assigns privileges to a user or role.
Example: GRANT SELECT, INSERT ON employees TO user_name;
○ REVOKE: Removes privileges from a user or role.
Example: REVOKE SELECT ON employees FROM user_name;
5. Transaction Control Language (TCL)
Q: Can you explain the importance of TCL in SQL?
● A: TCL stands for Transaction Control Language, which is used to manage transactions
in SQL. Transactions are important for ensuring data integrity. TCL commands include:
○ COMMIT: Saves the changes made during the current transaction to the
database.
Example: COMMIT;
○ ROLLBACK: Reverts the changes made during the current transaction, ensuring
that the database remains in a consistent state.
Example: ROLLBACK;
○ SAVEPOINT: Sets a point within a transaction to which you can roll back later.
Example: SAVEPOINT savepoint_name;
○ SET TRANSACTION: Configures the properties of a transaction, like isolation
levels.
Example: SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;