Table of Contents
Table of Contents
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
DROP DATABASE database_name
Table Manipulation
Create a database
Delete a database
Data Types
Data Type
Description
integer(size)
int(size)
Hold integers only. The maximum number of digits are specified in
parenthesis.
smallint(size)
tinyint(size)
decimal(size,d)
Hold numbers with fractions. The maximum number of digits are
specified in "size". The maximum number of digits to the right of the
numeric(size,d) decimal is specified in "d".
Holds a fixed length string (can contain letters, numbers, and special
char(size)
characters). The fixed size is specified in parenthesis.
Holds a variable length string (can contain letters, numbers, and special
varchar(size)
characters). The maximum size is specified in parenthesis.
date(yyyymmdd
Holds a date
)
Delete a table.
Delete a index.
UPDATE Person
SET Address = 'ups'
WHERE LastName = 'Hussein'
GROUP BY... was added to SQL because aggregate functions (like SUM) return the
aggregate of all column values every time they are called, and without the GROUP BY
FROM table_name
GROUP BY group_column_name
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
GROUP BY Company
WHERE query
SELECT column_name(s)
IN external_database_name
FROM source_table_name
WHERE query
CREATE VIEW
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
OTHER