Show Menu
Cheatography

SQL WTF Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

INTROD­UCTION

Why use a Database:

- Databases are accessible in any progra­mming language, meaning you can commun­icate large amount of datas between apps.

- Querying a database is really fast as it is relation based. So looking for all the items in a database matching specific criteria is lighting fast.

- Database are portable and secure.

WTF is seems so burried and inacce­ssible:

- At first databases concept if not explained right seems complex. The other reason for that is the amount of different uses for databases leading in different ways to explain it.

- If your just starting I suggest you to use both the terminal and a visual repres­ent­ation (GUI) of your database.
If your using it for the web using PHP or else, there should be a webapp to view your databases. For desktop your have MYSQL Workbench, SQL Workbench (opens­our­ce/­cro­ssp­latform and use drivers for each database framew­orks, hateful UI) or Postico ($). Specific to mac and Postgre you have PSequel
I personaly use pgAdmin

Install on mac

Using homebrew:
brew install postgresql this installs postgre
brew services start postgresqlthis runs the daemon
createdb -- create a database <us­er>

Create Password:
psql
\password <us­er>
\q to quit


Now to connect as the user
psql -U <us­er> -h localhost

To connect to a database
\c <da­tab­ase>

L I N K S

Nice explan­ation of accesing database in Python for Beginners
 

Queries

SELECT col1, col2, col3, ... FROM table1
filter your columns
WHERE col4 = 1 AND col5 = 2
filter the rows
ORDER BY col2
order of the results
BETWEEN a AND b
limit the range, the values can be numbers, text, or dates