Note: Parameters in [] can be omitted.

Table Creation

create table <table_name> (<column_name> <data_type> [column-level integrity constraints],
<column_name> <data_type> [column-level integrity constraints],
...,
<table-level integrity constraints>);

Table Modification

alter table <table_name>
[add [column] <new_column_name> <data_type> [integrity constraints]]
[add <table-level integrity constraint>]
[drop [column] <column_name> [cascade|restrict]]
[drop constraint <integrity_constraint_name> [restrict|cascade]]
[alter column <column_name> <data_type>];

Table Deletion

drop table <table_name> [cascade|restrict];

Query

select <target_column_expression> [,<target_column_expression>]...
from <table_name>
[group by <column_name1> [having <condition_expression>]]     -- Grouping
[order by <column_name2> [asc|desc]]             -- Ascending or descending

LIKE for Pattern Matching

where <column_name1> [not] like 'matching_string' [escape '<escape_character>']
  • % (percent sign) represents any string of arbitrary length (including length 0).
  • _ (underscore) represents any single character.

Insert Data

insert into <table_name> [(<attribute_column1> [,<attribute_column2>]...)] values (<constant1> [,<constant2>]...);

Insert Subquery Results

insert into <table_name> [(<attribute_column1> [,<attribute_column2>]...)]
select <target_column_expression1> [,<target_column_expression2>]...from <table_name>  -- Subquery result

Update Data

update <table_name> set <column_name>=<expression> [,<column_name>=<expression>...] [where <condition>];

Delete Data

delete from <table_name> [where <condition>];
Xiaoye