SQL Commands Reference

Data Definition Language (DDL)

Commands used to define, modify, and delete database objects.

CREATE TABLE

Creates a new table in the database.

CREATE TABLE Customers (
    CustomerID INT PRIMARY KEY,
    FirstName VARCHAR(50) NOT NULL,
    LastName VARCHAR(50) NOT NULL,
    Email VARCHAR(100) UNIQUE
);
ALTER TABLE

Modifies an existing table (add, delete, or modify columns).

ALTER TABLE Customers
ADD Phone VARCHAR(20);
DROP TABLE

Deletes a table and all its data.

DROP TABLE Customers;
CREATE DATABASE

Creates a new database.

CREATE DATABASE MyNewDatabase;
DROP DATABASE

Deletes an entire database.

DROP DATABASE MyNewDatabase;
Data Manipulation Language (DML)

Commands used to retrieve, insert, update, and delete data.

INSERT INTO

Inserts new records into a table.

INSERT INTO Customers (CustomerID, FirstName, LastName, Email)
VALUES (1, 'John', 'Doe', 'john.doe@example.com');
UPDATE

Modifies existing records in a table.

UPDATE Customers
SET Email = 'j.doe@example.com'
WHERE CustomerID = 1;
DELETE FROM

Deletes records from a table.

DELETE FROM Customers
WHERE CustomerID = 1;
Data Query Language (DQL)

Commands used to retrieve data from the database (primarily SELECT).

SELECT

Retrieves data from one or more tables.

SELECT FirstName, LastName, Email
FROM Customers
WHERE LastName = 'Doe'
ORDER BY FirstName ASC;
Transaction Control Language (TCL)

Manages transactions within the database.

COMMIT

Saves all transactions to the database.

COMMIT;
ROLLBACK

Undoes all transactions since the last COMMIT or ROLLBACK.

ROLLBACK;
SAVEPOINT

Sets a point within a transaction to which you can later roll back.

SAVEPOINT BeforeUpdate;
Data Control Language (DCL)

Commands used to control access to data and database objects.

GRANT

Gives users permission to perform specific actions on database objects.

GRANT SELECT, INSERT ON Customers TO User1;
REVOKE

Removes user permissions.

REVOKE INSERT ON Customers FROM User1;