SQL Cheat Sheet Conv
SQL Cheat Sheet Conv
Comprehensive
INSERT The INSERT command adds new INSERT INTO table_name INSERT INTO customers
records to a table. (column1, column2) (first_name,
VALUES (value1, value2); last_name) VALUES
('Mary', 'Doe');
UPDATE The UPDATE command is used UPDATE table_name SET
to modify existing records in a column1 = value1, column2 = UPDATE employees SET
table. value2 WHERE condition; employee_name = ‘John
Doe’, department =
‘Marketing’;
DELETE The D E L E T E command removes DELETE FROM table_name
records from a table. WHERE condition;
DELETE FROM employees
WHERE employee_name =
‘John Doe’;
CREATE The CREATE command creates a CREATE TABLE table_name CREATE TABLE employees
new database and objects, such (column1 datatype1, ( employee_id INT
as a table, index, view, or stored column2 datatype2, PRIMARY KEY,
procedure. ); first_name
VARCHAR(50),
last_name
VARCHAR(50),
age INT
);
GRANT The GRANT command is used to GRANT SELECT, INSERT ON GRANT SELECT, INSERT ON
give specific privileges to users table_name TO employees TO ‘John
or roles. user_name; Doe’;
INNER JOIN The INNER JOIN command SELECT * FROM SELECT * FROM employees
returns rows with matching table1 INNER JOIN INNER JOIN departments
values in both tables. table2 ON ON
table1.column = employees.department_id
table2.column; = departments.id;
SELECT
MAX(column_name) FROM
table_name;
The S Q L tool with the highest user satisfaction. DBVIS . CO M
String Functions in S Q L
DATE_SUB
Example SELECT
DATE_SUB('2024-04-
11', INTERVAL 1 DAY)
AS new_date;
SELECT
NULLIF(total_amount,
SELECT discounted_amount) AS
NULLIF(expression1, diff_amount FROM
expression2) AS orders;
alias FROM
table_name;
The S Q L tool with the highest user satisfaction. DBVIS . CO M
Set Operations
COMMIT;
ROLLBACK ; used to undo all the SQL statements and changes within the
changes made during the transaction
current transaction and
discard them.
INSERT INTO employees (name, age) VALUES ('Bob',
35); UPDATE products SET price = 30.00 WHERE
category = 'Electronics';
ROLLBACK;
The S Q L tool with the highest user satisfaction. DBVIS . CO M
SAVEPOINT The SAVEPOINT command SAVEPOINT BEGIN TRANSACTION;
is used to set a point within savepoint_n
a transaction to which you ame; INSERT INTO employees (name, age) VALUES
can later roll back. ('Carol', 28);
SAVEPOINT before_update;
SAVEPOINT after_update;
ROLLBACK TO before_update;
COMMIT;
SAVEPOINT after_update;
COMMIT;
COMMIT;
The S Q L tool with the highest user satisfaction. DBVIS . CO M