DDL (Data Definition Language) and DML (Data Manipulation Language) are two key subsets of SQL (Structured Query Language) that serve different purposes. Here's a breakdown:
DDL statements are used to define and manage database structures such as tables, indexes, and schemas. Common DDL statements include:
CREATE: Creates a new table, view, or other database objects.
Example: CREATE TABLE Employees (ID int, Name varchar(100), Age int);
ALTER: Modifies an existing database object, such as adding a column to a table.
Example: ALTER TABLE Employees ADD Salary decimal(10, 2);
DROP: Deletes an entire table, view, or another database object.
Example: DROP TABLE Employees;
TRUNCATE: Removes all rows from a table without logging individual row deletions.
Example: TRUNCATE TABLE Employees;
DML statements are used to manipulate data within existing database objects. Common DML statements include:
SELECT: Retrieves data from one or more tables.
Example: SELECT * FROM Employees;
INSERT: Adds new rows of data to a table.
Example: INSERT INTO Employees (ID, Name, Age) VALUES (1, 'John Doe', 30);
UPDATE: Modifies existing data within a table.
Example: UPDATE Employees SET Age = 31 WHERE ID = 1;
DELETE: Removes existing data from a table.
Example: DELETE FROM Employees WHERE ID = 1;
Each type of statement serves a unique role in managing and manipulating the data and structure of databases. Is there a specific DDL or DML query you'd like to see in action or need further explanation on?