Skip to content

Instantly share code, notes, and snippets.

@op01
Last active August 29, 2015 14:07
Show Gist options
  • Save op01/ba7193ab9ff318f994cf to your computer and use it in GitHub Desktop.
Save op01/ba7193ab9ff318f994cf to your computer and use it in GitHub Desktop.

SQL Cheat Sheet

CRUD

  1. Create
  • insert (all colunms)
insert into T values(V1,V2,V3)
  • insert (some columns)
insert into T(C1,C2) values(V1,V2)
  1. Read
  • select all colums from T
select * from T
  • select C1 and C2 from T
select C1,C2 from T
  • select by CONDITIONS
select * from T where CONDITIONS
  • select order by column C1
select * from T order by C1
  1. Update
  • update by CONDITIONS
update set C1=V2,C2=V2 where CONDITIONS
  1. Delete
  • delete all records
delete from T
  • delete by CONDITIONS
delete from T where CONDITIONS

Conditions

  1. Range
select * from T where C1 [not] between V1 and V2
  1. Equal
select * from T where C1=V1 and C2<>V2
  1. List
select * from T where C1 [not] in (V1,V2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment