Database Languages

A database language is used to define, access, manipulate, and control data in a DBMS. Four categories — remember DDL · DML · DCL · TCL.

Memory hook: Define (DDL) · Manipulate (DML) · Control access (DCL) · Transactions (TCL).

DDL — Data Definition Language

Defines and changes the structure (schema) of database objects (tables, views, indexes).

Commands: CREATE, ALTER, DROP, TRUNCATE, RENAME.

CREATE TABLE Student (
  student_id INT PRIMARY KEY,
  name VARCHAR(50),
  dept VARCHAR(30)
);

ALTER TABLE Student ADD email VARCHAR(60);

DML — Data Manipulation Language

Works with the data (rows) inside tables — insert, update, delete, query.

Commands: SELECT, INSERT, UPDATE, DELETE.

INSERT INTO Student(student_id, name, dept)
VALUES (1, 'Rahim', 'CSE');

UPDATE Student SET dept = 'EEE' WHERE student_id = 1;

SELECT * FROM Student;
Two classes of query languages:
Pure (for proving properties / optimization): Relational Algebra, Tuple relational calculus, Domain relational calculus.
Commercial (real systems): SQL is the most widely used.

DCL — Data Control Language

Controls access / permissions (security) on database objects.

Commands: GRANT, REVOKE.

GRANT SELECT, INSERT ON Student TO user1;
REVOKE INSERT ON Student FROM user1;

TCL — Transaction Control Language

Manages transactions to ensure consistency (commit, rollback, savepoints).

Commands: COMMIT, ROLLBACK, SAVEPOINT, SET TRANSACTION.

SAVEPOINT sp1;
UPDATE Student SET dept = 'CE' WHERE student_id = 1;
ROLLBACK TO sp1;   -- undo after savepoint
COMMIT;            -- permanently save

One-line summary

TypeActs onKey commands
DDLSchema / structureCREATE, ALTER, DROP, TRUNCATE
DMLRows / dataSELECT, INSERT, UPDATE, DELETE
DCLPermissionsGRANT, REVOKE
TCLTransactionsCOMMIT, ROLLBACK, SAVEPOINT

Try these in the SQL Playground →