0% found this document useful (0 votes)
2 views7 pages

SQL Cheat Sheet

This document is a SQL cheat sheet that outlines key commands in Data Manipulation Language (DML), Data Definition Language (DDL), and Data Control Language (DCL). It provides syntax and examples for commands such as SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and GRANT. Additionally, it includes information on querying data commands like WHERE, ORDER BY, GROUP BY, and HAVING clauses.

Uploaded by

shifakhan11045
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

SQL Cheat Sheet

This document is a SQL cheat sheet that outlines key commands in Data Manipulation Language (DML), Data Definition Language (DDL), and Data Control Language (DCL). It provides syntax and examples for commands such as SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and GRANT. Additionally, it includes information on querying data commands like WHERE, ORDER BY, GROUP BY, and HAVING clauses.

Uploaded by

shifakhan11045
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SQL cheat sheet

Data Manipulation Language DML Commands


Command Description Syntax Example
SELECT The SELECT command SELECT column1, SELECT first_name, last_name
retrieves column2 FROM FROM customers;
data from a database. table_name;

INSERT The INSERT command INSERT INTO INSERT INTO customers


adds new table_name (first_name, last_name)
records to a table. (column1, VALUES ('Mary', 'Doe');
column2) VALUES
(value1, value2);
UPDATE The UPDATE command UPDATE UPDATE employees SET
is used table_name SET employee_name = ‘John Doe’,
to modify existing column1 department = ‘Marketing’;
records in a = value1, column2
table. = value2
WHERE condition;
DELETE The DELETE command DELETE FROM DELETE FROM employees WHERE
removes table_name employee_name = ‘John Doe’;
records from a table. WHERE condition;

Data Definition Language DDL Commands


Command Description Syntax Example
CREATE The CREATE command CREATE TABLE CREATE TABLE employees
creates a table_name (employee_id INT PRIMARY KEY,
new database and (column1 datatype1, first_name VARCHAR(50),
objects, such column2 datatype2, ); last_name VARCHAR(50),age INT);
as a table, index, view,
or stored
procedure.
ALTER The ALTER command ALTER TABLE ALTER TABLE customers ADD
adds, table_name email VARCHAR(100);
deletes, or modifies ADD column_name
columns in datatype;
an existing table.
DROP The DROP command is DROP TABLE DROP TABLE customers;
used to table_name;
drop an existing table in
a database.
TRUNCATE The TRUNCATE TRUNCATE TABLE TRUNCATE TABLE customers;
command is table_name;
used to delete the data
inside a
table, but not the table
itself.
Data Control Language DCL Commands
Command Description Syntax Example
GRANT The GRANT command is GRANT SELECT, INSERT GRANT SELECT, INSERT ON
used to ON employees TO ‘John Doe’;
give specific privileges to table_name TO
users user_name;
or roles.
REVOKE The REVOKE command is REVOKE SELECT, INSERT REVOKE SELECT, INSERT ON
used ON employees FROM ‘John
to take away privileges table_name FROM Doe’;
previously granted to users user_name;
or
roles.

Querying Data Commands


Command Description Syntax Example
SELECT Statement The SELECT SELECT column1, column2 SELECT first_name,
statement is the FROM table_name; last_name FROM customers;
primary command used to
retrieve data from a
database
WHERE Clause The WHERE clause is SELECT * FROM SELECT * FROM customers
used to table_name WHERE age > 30;
filter rows based on a WHERE condition;
specified
condition.
ORDER BY Clause The ORDER BY clause SELECT * FROM SELECT * FROM products
is used to table_name ORDER BY price DESC;
sort the result set in ORDER BY column_name
ascending ASC|DESC;
or descending order based
on a
specified column.

GROUP BY Clause The GROUP BY clause groups SELECT column_name, SELECT category, COUNT(*)
rows based on the values in COUNT(*) FROM FROM products GROUP BY
a table_name category;
specified column. It is often GROUP BY column_name;
used with aggregate
functions
like COUNT, SUM, AVG, etc.
HAVING Clause The HAVING clause filters SELECT column_name,
grouped results based on a COUNT(*) FROM SELECT category, COUNT(*)
specified condition. table_name FROM products GROUP BY
GROUP BY column_name category HAVING COUNT(*)
HAVING condition; > 5;
Joins in SQL
Normal Form
1st Normal Form 2nd Normal Form

3rd Normal Form

You might also like