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

SQL (Structured Query Language) in One Page - SQL - Su

This document provides a comprehensive overview of SQL (Structured Query Language) including database manipulation, table manipulation, index manipulation, data manipulation, and various SQL commands such as SELECT, INSERT, UPDATE, and DELETE. It also covers data types, operators, aggregate functions, joins, and the creation of views. The content serves as a quick reference guide for SQL syntax and operations.
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 views3 pages

SQL (Structured Query Language) in One Page - SQL - Su

This document provides a comprehensive overview of SQL (Structured Query Language) including database manipulation, table manipulation, index manipulation, data manipulation, and various SQL commands such as SELECT, INSERT, UPDATE, and DELETE. It also covers data types, operators, aggregate functions, joins, and the creation of views. The content serves as a quick reference guide for SQL syntax and operations.
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

07/02/2026, 13:49 SQL (Structured Query Language) in one page : SQL.

SU

SQL (Structured Query Language) in o


Table of contents: Database Manipulation (CREATE, DROP DATABASE), Table Manipulation (CREATE, ALTER, DROP
TABLE, Data Types), Index Manipulation (CREATE, DROP INDEX), Data Manipulation (INSERT, UPDATE, DELETE,
TRUNCATE TABLE), Select (SELECT, FROM, WHERE, ORDER BY, GROUP BY, HAVING, Operators, Aggregate functions),
Alias, Join, UNION, SELECT INTO/IN, CREATE VIEW.

Database Manipulation
CREATE DATABASE database_name Create a database CREATE DATABASE My_Fi
DROP DATABASE database_name Delete a database DROP DATABASE My_First
Table Manipulation
CREATE TABLE "table_name" Create a table in a database. CREATE TABLE Person
("column_1" "data_type_for_column_1", (LastName varchar,
Data Types
"column_2" "data_type_for_column_2", FirstName varchar,
... ) Data Type Description Address varchar,
integer(size) Hold integers only. The maximum Age int)
int(size) number of digits are specified in
smallint(size) parenthesis.
tinyint(size)
decimal(size,d) Hold numbers with fractions. The
maximum number of digits are
specified in "size". The maximum
numeric(size,d) number of digits to the right of the
decimal is specified in "d".
char(size) Holds a fixed length string (can
contain letters, numbers, and special
characters). The fixed size is specified
in parenthesis.
varchar(size) Holds a variable length string (can
contain letters, numbers, and special
characters). The maximum size is
specified in parenthesis.
date(yyyymmdd) Holds a date
ALTER TABLE table_name ADD column_name datatype Add columns in an existing table. ALTER TABLE Person ADD
ALTER TABLE table_name DROP column_name datatype Delete columns in an existing table. ALTER TABLE Person DROP
DROP TABLE table_name Delete a table. DROP TABLE Person
Index Manipulation
CREATE INDEX index_name Create a simple index. CREATE INDEX PersonIndex
ON table_name (column_name_1, column_name_2, ...) ON Person (LastName, FirstN
CREATE UNIQUE INDEX index_name Create a unique index. CREATE UNIQUE INDEX P
ON table_name (column_name_1, column_name_2, ...) ON Person (LastName DESC)
DROP INDEX table_name.index_name Delete a index. DROP INDEX [Link]
Data Manipulation
INSERT INTO table_name Insert new rows into a table. INSERT INTO Persons
VALUES (value_1, value_2,....) VALUES('Hussein', 'Saddam',
INSERT INTO table_name (column1, column2,...) INSERT INTO Persons (LastN
VALUES (value_1, value_2,....) VALUES('Hussein', 'Saddam',
UPDATE table_name Update one or several columns in rows. UPDATE Person
SET column_name_1 = new_value_1, column_name_2 = SET Address = 'ups'
new_value_2 WHERE LastName = 'Hussein
WHERE column_name = some_value
DELETE FROM table_name Delete rows in a table. DELETE FROM Person WHE
WHERE column_name = some_value
TRUNCATE TABLE table_name Deletes the data inside the table. TRUNCATE TABLE Person
Select
SELECT column_name(s) FROM table_name Select data from a table. SELECT LastName, FirstNam
SELECT * FROM table_name Select all data from a table. SELECT * FROM Persons
SELECT DISTINCT column_name(s) FROM table_name Select only distinct (different) data from a table. SELECT DISTINCT LastNam
SELECT column_name(s) FROM table_name Select only certain data from a table. SELECT * FROM Persons W
WHERE column operator value SELECT * FROM Persons W
Operators
AND column operator value
OR column operator value Operator Description SELECT * FROM Persons
AND (... OR ...) WHERE FirstName='Saddam
= Equal AND LastName='Hussein'
... <> Not equal
SELECT * FROM Persons
> Greater than WHERE FirstName='Saddam
< Less than OR LastName='Hussein'
>= Greater than or equal
SELECT * FROM Persons W
<= Less than or equal (FirstName='Tove' OR FirstNa
BETWEEN Between an inclusive range AND LastName='Svendson'

[Link]/sites/[Link]/ 1/3
07/02/2026, 13:49 SQL (Structured Query Language) in one page : [Link]
LIKE Search for a pattern. SELECT * FROM Persons W
A "%" sign can be used to define wildcards SELECT * FROM Persons W
(missing letters in the pattern) both before
and after the pattern. SELECT * FROM Persons W
SELECT column_name(s) FROM table_name The IN operator may be used if you know the exact value SELECT * FROM Persons
WHERE column_name IN (value1, value2, ...) you want to return for at least one of the columns. WHERE LastName IN ('Hans
SELECT column_name(s) FROM table_name Select data from a table with sort the rows. SELECT * FROM Persons
ORDER BY row_1, row_2 DESC, row_3 ASC, ... ORDER BY LastName
Note:
SELECT FirstName, LastNam
ASC (ascend) is a alphabetical and numerical order ORDER BY LastName DESC
(optional)
DESC (descend) is a reverse alphabetical and numerical SELECT Company, OrderNum
order ORDER BY Company DESC

SELECT column_1, ..., SUM(group_column_name) GROUP BY... was added to SQL because aggregate SELECT Company, SUM(Am
FROM table_name functions (like SUM) return the aggregate of all column values FROM Sales
GROUP BY group_column_name every time they are called, and without the GROUP BY GROUP BY Company
function it was impossible to find the sum for each individual
group of column values.
Some aggregate functions
Function Description
AVG(column) Returns the average value of a
column
COUNT(column) Returns the number of rows (without
a NULL value) of a column
MAX(column) Returns the highest value of a
column
MIN(column) Returns the lowest value of a
column
SUM(column) Returns the total sum of a column
SELECT column_1, ..., SUM(group_column_name) HAVING... was added to SQL because the WHERE SELECT Company, SUM(Am
FROM table_name keyword could not be used against aggregate functions (like FROM Sales
GROUP BY group_column_name SUM), and without HAVING... it would be impossible to test GROUP BY Company
HAVING SUM(group_column_name) condition value for result conditions. HAVING SUM(Amount)>100
Alias
SELECT column_name AS column_alias FROM table_name Column name alias SELECT LastName AS Famil
FROM Persons
SELECT table_alias.column_name FROM table_name AS Table name alias SELECT LastName, FirstNam
table_alias FROM Persons AS Employee
Join
SELECT column_1_name, column_2_name, ... The INNER JOIN returns all rows from both tables where SELECT [Link], O
FROM first_table_name there is a match. If there are rows in first table that do not have FROM Employees
INNER JOIN second_table_name matches in second table, those rows will not be listed. INNER JOIN Orders
ON first_table_name.keyfield = ON Employees.Employee_ID
second_table_name.foreign_keyfield
SELECT column_1_name, column_2_name, ... The LEFT JOIN returns all the rows from the first table, SELECT [Link], O
FROM first_table_name even if there are no matches in the second table. If there are FROM Employees
LEFT JOIN second_table_name rows in first table that do not have matches in second table, LEFT JOIN Orders
ON first_table_name.keyfield = those rows also will be listed. ON Employees.Employee_ID
second_table_name.foreign_keyfield
SELECT column_1_name, column_2_name, ... The RIGHT JOIN returns all the rows from the second SELECT [Link], O
FROM first_table_name table, even if there are no matches in the first table. If there had FROM Employees
RIGHT JOIN second_table_name been any rows in second table that did not have matches in first RIGHT JOIN Orders
ON first_table_name.keyfield = table, those rows also would have been listed. ON Employees.Employee_ID
second_table_name.foreign_keyfield
UNION
SQL_Statement_1 Select all different values from SQL_Statement_1 and SELECT E_Name FROM Em
UNION SQL_Statement_2 UNION
SQL_Statement_2 SELECT E_Name FROM Em
SQL_Statement_1 Select all values from SQL_Statement_1 and SELECT E_Name FROM Em
UNION ALL SQL_Statement_2 UNION
SQL_Statement_2 SELECT E_Name FROM Em
SELECT INTO/IN
SELECT column_name(s) Select data from table(S) and insert it into another table. SELECT * INTO Persons_bac
INTO new_table_name
FROM source_table_name
WHERE query
SELECT column_name(s) Select data from table(S) and insert it in another database. SELECT Persons.* INTO Per
IN external_database_name Persons WHERE City='Sandn
FROM source_table_name
WHERE query
CREATE VIEW
CREATE VIEW view_name AS Create a virtual table based on the result-set of a SELECT CREATE VIEW [Current Prod
SELECT column_name(s) statement. SELECT ProductID, ProductN
FROM table_name FROM Products
WHERE condition WHERE Discontinued=No

[Link]/sites/[Link]/ 2/3
07/02/2026, 13:49 SQL (Structured Query Language) in one page : [Link]

OTHER
Public Domain 2006-2016 Alexander Krassotkin

[Link]/sites/[Link]/ 3/3

You might also like