SQL Commands: DDL, DML, DCL
1. Data Definition Language (DDL)
1. Data Definition Language (DDL):
DDL commands are used to define and modify the structure of database objects such as tables, indexes, and
schemas.
Common DDL Commands:
- CREATE: To create new tables or databases.
- ALTER: To modify existing table structures.
- DROP: To delete tables or databases.
- TRUNCATE: To remove all records from a table without logging individual row deletions.
Examples:
CREATE TABLE Students (
StudentID INT,
Name VARCHAR(50),
Age INT
);
ALTER TABLE Students ADD Email VARCHAR(100);
DROP TABLE Students;
2. Data Manipulation Language (DML)
2. Data Manipulation Language (DML):
SQL Commands: DDL, DML, DCL
DML commands are used to manipulate data stored in the database. They allow inserting, updating, deleting,
and retrieving data.
Common DML Commands:
- INSERT: To add new records.
- UPDATE: To modify existing records.
- DELETE: To remove records.
- SELECT: To retrieve data.
Examples:
INSERT INTO Students (StudentID, Name, Age) VALUES (101, 'Alice', 21);
UPDATE Students SET Age = 22 WHERE StudentID = 101;
DELETE FROM Students WHERE StudentID = 101;
SELECT * FROM Students;
3. Data Control Language (DCL)
3. Data Control Language (DCL):
DCL commands are used to control access to data in the database. They deal with permissions and access
rights.
Common DCL Commands:
SQL Commands: DDL, DML, DCL
- GRANT: To give privileges to users.
- REVOKE: To remove privileges from users.
Examples:
GRANT SELECT, INSERT ON Students TO user1;
REVOKE INSERT ON Students FROM user1;