SQL Cheat Sheet
SQL Cheat Sheet
What How
Common MySQL Column Types
Count rows per group COUNT(column | *)
Purpose Data Type Example Average value of group AVG(column)
Integers int(M) int(5)
Minumum value of group MIN(column)
Floating-point (real) numbers float(M,D) float(12,3)
Maximum value of group MAX(column)
Double-precision floating-point double(M,D) double(20,3) Sum values in a group SUM(column)
Dates and times timestamp(M) timestamp(8) (for YYYYMMDD) Absolute value abs(number)
timestamp(12) (for
YYYYMMDDHHMMSS) Rounding numbers round(number)
Fixed-length strings char(M) char(10) Largest integer not greater floor(number)
Smallest integer not smaller ceiling(number)
Variable-length strings varchar(M) varchar(20)
Square root sqrt(number)
A large amount of text blob blob
nth power pow(base,exponent)
Values chosen from a list enum('value1',value2) enum('apples','oranges','bananas') random number n, 0<n < 1 rand()
M is maximum to display, and D is precision to the right of the decimal. sin (similar cos, etc.) sin(number)
G WORKS
SQL Commands: Modifying
What How Example(s)
CREATE TABLE table ( CREATE TABLE Students (
column1 type [[NOT] NULL] LastName varchar(30) NOT NULL,
[AUTO_INCREMENT], FirstName varchar(30) NOT NULL,
Create table column2 type [[NOT] NULL] StudentID int NOT NULL,
[AUTO_INCREMENT], Major varchar(20),
... Dorm varchar(20),
other options, PRIMARY KEY (StudentID) );
PRIMARY KEY (column(s)) );