SQL Cheatsheet
SQL Cheatsheet
CHEATSHEET
Contact Us
+916381057440
www.digyquant.com
Structured Query Language, is a standard language for interacting with relational databases. It is used to manage and organize data in all kinds of systems in
which various data relationships need to be managed. There are several types of SQL commands, and they can be divided into different categories based on
their functions. Three of these categories are Data Definition Language (DDL), Data Manipulation Language (DML), and Control Language (CL).
These are commands that define the database structure or schema. It allows you to These are commands used to control
DDL CREATE, ALTER, and DROP the database objects like table, index, sequence, views, etc. DCL the privileges on the database objects.
DCL is used to manage the rights or
CREATE: Creates a new table or database. ALTER: Modifies an existing database object.
Command permissions that are provided to a
DROP: Deletes an entire table or database. TRUNCATE: Deletes all records from a table.
database user.
These are commands used for manipulating the data present in the database. DML allows
DML you to work with the data that is present in the database like inserting data, updating Command GRANT: Gives user's access privileges
to the database.
data, retrieving data, and deleting data from the database.
REVOKE: Takes back access privileges
SELECT: Retrieves data from the database. INSERT: Inserts data into a table.
Command given to the user.
UPDATE: Modifies data in a table. DELETE: Deletes data from a table.
SELECT (All Columns) Select all columns from a table. CREATE TABLE Create a new table
SELECT (Specific Columns) Select specific columns from a table.
ALTER TABLE (Add Column) Add a new column to a table
SELECT DISTINCT Select distinct (different) values of a column.
ALTER TABLE (Modify Column) Modify an existing column in a table
WHERE Filter records that fulfill a specified condition.
ALTER TABLE (Rename Column) Rename an existing column in a table
AND, OR, NOT Combine conditions.
ORDER BY (Ascending) Sort the results in ascending order. ALTER TABLE (Drop Column) Remove a column in a table
ORDER BY (Descending) Sort the results in descending order. ALTER TABLE (Add Primary Key) Add a primary key to a table
COUNT Count the number of rows that match a specified condition.
ALTER TABLE (Drop Primary Key) Remove a primary key from a table
GROUP BY Group rows that have the same values in specified columns into aggregated data.
ALTER TABLE (Add Foreign Key) Add a foreign key to a table
HAVING Filter the results of a GROUP BY.
INNER JOIN Combine rows from different tables if they meet a certain condition. ALTER TABLE (Drop Foreign Key) Remove a foreign key from a table
LEFT JOIN Return all records from the left table, and the matched records from the right table. CHECK Constraint Ensure that all values in a column satisfy a condition
RIGHT JOIN Return all records from the right table, and the matched records from the left table.
UNIQUE Constraint Ensure that all values in a column are unique
FULL OUTER JOIN Return all records when there is a match in either the left or the right table.
ALTER TABLE (Delete Constraint) Delete a constraint
UNION Combine the result set of two or more SELECT statements (only distinct values).
UNION ALL Combine the result set of two or more SELECT statements (allows duplicate values). DROP TABLE Remove a table
NULL VALUES Select rows where column value is NULL. RENAME TABLE Rename a table
NOT NULL VALUES Select rows where column value is not NULL.
TRIM Remove leading and trailing spaces from a string.
LIKE Search for a specified pattern in a column.
SUBSTRING Extract a part of a string.
IN Specify multiple possible values for a column.
BETWEEN Select values within a given range. COALESCE Return the first non-null value in a list.
ALIASES Give a table or a column a temporary name. DATE Functions Work with dates.
UPDATE with JOIN Update a table using data from another table.
TRUNCATE TABLE Delete all records from a table, without deleting the table
INSERT INTO SELECT Copy data from one table and insert it into another table.
CASE
EXISTS
Implement IF-THEN-ELSE logic.
Test for the existence of any record in a subquery.
Digyquant Benefits
ANY and ALL Compare a value to each value in a list or returned by a query. 1:1 Mentorship from In-Depth Q&A and
SELECT INTO Create a new table and fill it with data from a selected table. Industry experts Clarification
INSERT Multiple Rows Insert multiple rows into a table.
LIMIT Restrict the number of rows returned by a query. 24x7 Live 1:1 Video based Hands-On Learning with
FETCH Retrieve a single row or multiple rows. doubt support Projects and Exercises
OFFSET Skip a specified number of rows before returning the result set.
Mentors with 12+ years of experience
ISNULL() Function Replace NULL values with another value.