Database Languages in DBMS (DDL & DML)

Database Languages are special commands used to define, store, manipulate, and control data in a database. They provide a way for users and applications to interact with databases.

1. What are Database Languages?

Database languages are used to communicate with the database. They help in creating database structures, inserting data, retrieving data, and managing access control.

2. Types of Database Languages

3. Data Definition Language (DDL)

DDL is used to define and modify the structure of database objects such as tables, databases, indexes, and views.

🔹 Common DDL Commands

CREATE    → Creates database objects
ALTER     → Modifies structure
DROP      → Deletes objects
TRUNCATE  → Removes all records
RENAME    → Renames database objects

🔹 Example (CREATE TABLE)

CREATE TABLE Student (
    RollNo INT,
    Name VARCHAR(50),
    Marks INT
);

4. Data Manipulation Language (DML)

DML is used to insert, update, delete, and retrieve data stored in tables.

🔹 Common DML Commands

INSERT   → Adds new records
UPDATE   → Modifies existing records
DELETE   → Removes records
SELECT   → Retrieves data

🔹 Example (INSERT & SELECT)

INSERT INTO Student VALUES (101, 'Amit', 78);

SELECT * FROM Student;

5. Difference between DDL and DML

DDL                         DML
-------------------------   --------------------------
Defines database structure  Manipulates data
Auto-commit                 Needs commit/rollback
Affects schema              Affects table data

6. Data Control Language (DCL)

DCL is used to control access to the database and provide authorization.

GRANT  → Gives permission
REVOKE → Removes permission

7. Transaction Control Language (TCL)

TCL is used to manage transactions in a database.

COMMIT    → Save changes
ROLLBACK  → Undo changes
SAVEPOINT → Set rollback point

8. Importance of Database Languages

Practice Questions

  1. What are database languages?
  2. Explain DDL with examples.
  3. Explain DML with examples.
  4. Differentiate between DDL and DML.
  5. What is DCL and TCL?

Practice Task

Write SQL queries to: ✔ Create a table ✔ Insert records ✔ Update records ✔ Delete records ✔ Grant permission to a user