DML, DDL, and DBMS Explained

DML, DDL, and DBMS Explained

1. What is DBMS (Database Management System)?

A DBMS (Database Management System) is software that manages databases and provides an interface to interact with stored data. Examples: MySQL, PostgreSQL, Oracle, SQL Server.

📌 Types of DBMS:

  • Relational DBMS (RDBMS) – Uses structured tables (e.g., MySQL, PostgreSQL).
  • NoSQL DBMS – Works with unstructured or semi-structured data (e.g., MongoDB).

2. What is DDL (Data Definition Language)?

DDL (Data Definition Language) is used to define or modify database structures such as tables, schemas, and indexes.

📌 Common DDL Commands:

Command Description
CREATE Creates a new table or database.
ALTER Modifies an existing database structure.
DROP Deletes a table or database permanently.
TRUNCATE Deletes all records from a table but keeps structure.

✅ Example DDL Queries:


CREATE TABLE employees (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    salary DECIMAL(10,2)
);

ALTER TABLE employees ADD COLUMN department VARCHAR(50);

DROP TABLE employees;

    

3. What is DML (Data Manipulation Language)?

DML (Data Manipulation Language) is used to insert, update, delete, and retrieve data in a database.

📌 Common DML Commands:

Command Description
SELECT Retrieves data from a database.
INSERT Adds new records to a table.
UPDATE Modifies existing data.
DELETE Removes records from a table.

✅ Example DML Queries:


INSERT INTO employees (id, name, salary) VALUES (1, 'John Doe', 50000);

UPDATE employees SET salary = 55000 WHERE id = 1;

DELETE FROM employees WHERE id = 1;

SELECT * FROM employees;

    

Key Differences: DDL vs. DML

Feature DDL (Data Definition Language) DML (Data Manipulation Language)
Purpose Defines database structure Manages and modifies data
Commands CREATE, ALTER, DROP, TRUNCATE SELECT, INSERT, UPDATE, DELETE
Rollback Changes cannot be undone Changes can be rolled back
Example CREATE TABLE users (...) INSERT INTO users (...)

Conclusion

  • DBMS manages databases.
  • DDL is used for defining database structure.
  • DML is used for manipulating data.

Would you like more examples or deeper explanations? 😊