Loading
Types of SQL Commands

Q1. What are SQL commands and why are they categorized?
SQL commands are instructions that allow users to interact with a database. They tell the database what action to perform, such as creating tables, inserting data, retrieving records, or controlling access.

SQL commands are categorized because not all commands perform the same type of work. Some commands deal with database structure, some with data, some with security, and some with transactions. Categorizing SQL commands helps developers and database administrators clearly understand the purpose of each command and use them correctly.

By grouping commands, SQL becomes easier to learn, maintain, and use efficiently in real-world applications.


Q2. Explain DDL (Data Definition Language) with examples.
DDL stands for Data Definition Language. These commands are used to define, modify, or remove the structure of database objects such as tables, views, and indexes.

DDL commands work directly on the database structure and usually auto-commit changes, meaning they cannot be rolled back easily.

Common DDL commands include:

  • CREATE - Creates database objects
  • ALTER - Modifies existing objects
  • DROP - Deletes objects completely
  • TRUNCATE - Deletes all data from a table but keeps its structure

Example:

CREATE TABLE Students (
    ID INT,
    Name VARCHAR(50)
);

DDL commands are mainly used during database design and schema changes.


Q3. What is DML and how is it different from DDL?
DML stands for Data Manipulation Language. These commands are used to manage the data stored inside database tables.

Unlike DDL, which changes structure, DML works on the actual records (rows). DML commands are transaction-based, meaning changes can be rolled back before committing.

Common DML commands include:

  • INSERT - Adds new records
  • UPDATE - Modifies existing records
  • DELETE - Removes records
  • SELECT - Retrieves data
DDL defines what the table looks like, while DML controls what data the table contains.


Q4. Explain DCL and its importance.
DCL stands for Data Control Language. These commands are used to control access and permissions in a database. They ensure database security by defining who can access or modify data.


Common DCL commands include:

  • GRANT - Gives permissions to users
  • REVOKE - Removes permissions from users
DCL commands are mostly used by database administrators to protect sensitive data and prevent unauthorized access.


Q5. What is TCL and why is it required?
TCL stands for Transaction Control Language. These commands manage transactions in a database, ensuring data consistency and reliability.

A transaction is a group of SQL operations that must either all succeed or all fail.


Common TCL commands include:

  • COMMIT - Saves changes permanently
  • ROLLBACK - Reverts uncommitted changes
  • SAVEPOINT - Creates a point to rollback partially
TCL is essential in applications like banking systems where data accuracy is critical.


Q6. What is DQL and how is it different from DML?
DQL stands for Data Query Language and is mainly used to retrieve data from databases. It primarily includes the SELECT command.

Although some databases classify SELECT under DML, many treat it separately because it does not modify data it only queries it.


Example:

SELECT Name, Age FROM Students WHERE Age > 20;