Notes

Notes on SQL

Edit on GitHub

Databases
  • Schema is greek for shape. It’s the shape or structure of your data
1mysqladmin create 'DBNAME';
2mysqladmin drop 'DBNAME';
1-- getting data
2SELECT * FROM Employee; -- bad idea, extra data coming through.
3SELECT id, firstname, lastname FROM Employee -- good, less I/O. select your columns, returned in order of asking
1-- quotes, double quotes, and backticks
2SELECT Id FROM Employee -- stick to the first two preferred format to avoid inconsistencies
3SELECT id FROM Employee -- table, column names are usually case-insensitive
4SELECT 'id' FROM Employee -- single quotes for string literals, literal values and not columns!
5SELECT "Id" FROM Employee -- double quotes for words that conflict with SQL keywords, or case-sensitivity desired
6SELECT `Id` FROM Employee -- sames as double quotes, MySQL only
1-- use AS keywords to alias a column
2SELECT 
3	p.productname AS title
4FROM
5	Product as p