Home » Database Management System » Unit 1: Introduction » Explain all database languages in detail with examples.

Explain all database languages in detail with examples.

Support this post with a reaction:

5,128 views

To use a database, we need different types of commands. It depends on what we want to do design tables, change data, control user access, or manage transactions.

These commands are grouped into 4 main types.

1. Data Definition Language (DDL)

DDL is used to create and change the structure of the database – like tables. It works on the table design, not on the actual data rows.

CommandWhat it doesExample
CREATEBuilds a new table or schemaCREATE TABLE Student (RollNo INT PRIMARY KEY, Name VARCHAR(30), Marks INT);
ALTERChanges an existing table (adds or removes columns)ALTER TABLE Student ADD Email VARCHAR(50);
DROPDeletes the table completely, along with its structure and dataDROP TABLE Student;

2. Data Manipulation Language (DML)

DML is used to work with the actual data stored inside the tables.

CommandWhat it doesExample
INSERTAdds new rows of dataINSERT INTO Student VALUES (101, ‘Aman’, 85, ‘aman@email.com’);
UPDATEChanges existing data valuesUPDATE Student SET Marks = 90 WHERE RollNo = 101;
DELETERemoves rows based on a conditionDELETE FROM Student WHERE RollNo = 101;
SELECTFetches data from tablesSELECT Name, Marks FROM Student WHERE Marks > 80;

3. Data Control Language (DCL)

DCL is used by the Database Administrator (DBA) to control who can access what, and to keep the data secure.

CommandWhat it doesExample
GRANTGives specific permission to a userGRANT SELECT, INSERT ON Student TO User_Rohan;
REVOKETakes back permission from a userREVOKE INSERT ON Student FROM User_Rohan;

4. Transaction Control Language (TCL)

TCL commands manage the changes made by DML commands. They make sure the database stays correct and safe during a transaction (a group of operations).

CommandWhat it doesExample
COMMITSaves all changes permanentlyCOMMIT;
ROLLBACKUndoes changes and goes back to the last saved point (used when there is an error)ROLLBACK;
SAVEPOINTCreates a checkpoint in a transaction, so we can roll back to that exact point instead of undoing everythingSAVEPOINT SP1;