Notes on SQL

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