Data Manipulation Language (DML) statements are used to manage data within schema objects. DML statements include INSERT, UPDATE, DELETE, and SELECT.
The INSERT statement is used to add new rows of data to a table.
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
INSERT INTO Employees (FirstName, LastName, HireDate)
VALUES ('John', 'Doe', '2023-10-26');
INSERT INTO Departments
VALUES ('HR', 'Human Resources', 'New York');
The UPDATE statement is used to modify existing records in a table.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
UPDATE Employees
SET Salary = 60000
WHERE EmployeeID = 101;
UPDATE Products
SET Price = Price * 1.10 -- Increase price by 10%
WHERE CategoryID = 3;
The DELETE statement is used to remove rows from a table.
DELETE FROM table_name
WHERE condition;
DELETE FROM Customers
WHERE CustomerID = 50;
DELETE FROM Orders;
TRUNCATE TABLE table_name;
The SELECT statement is used to retrieve data from one or more tables.
SELECT column1, column2, ...
FROM table_name
WHERE condition;
SELECT *
FROM Products;
SELECT ProductName, Price
FROM Products
WHERE CategoryID = 2
ORDER BY Price DESC;
SELECT o.OrderID, c.CustomerName
FROM Orders AS o
JOIN Customers AS c ON o.CustomerID = c.CustomerID;
WHERE: Filters records based on a specified condition.ORDER BY: Sorts the result set in ascending or descending order.GROUP BY: Groups rows that have the same values in specified columns into summary rows.HAVING: Filters groups based on a specified condition (used with GROUP BY).JOIN: Combines rows from two or more tables based on a related column.