SQL CheatsheetTue Oct 27 2020

If I need to look up multiple times, I should just record it in my own cheatsheet.

BEGIN TRANSACTION
sql-request
ROLLBACK TRANSACTION OR COMMIT TRANSACTION

Allows you to see what would be changed with ROLLBACK or make the change and know what was changed with COMMIT

! is written as NOT

coalesce(variable, false) checks if the variable is null or false

All variables with capital letters need quotes around them

Migrations are sorted by timestamp. New migrations should have the largest timestamp in the name.

LIKE is equivalent to = unless wildcards are used WHERE column_name LIKE '%input%'

EXPLAIN lists who what processes were run and costs - If it's in the 4 digits it's not too bad. Seq Scan are painful and solved through indexing columns.

Count the number of rows in a table

PGSL

\d describe all tables

\q quit

SELECT COUNT(*)
FROM my_table

Comments are prefixed with --

SQL Join Types

Query Formatter