- What is the difference between a schema and a database?
- In PostgreSQL, a schema is a namespace within a database that contains tables, views, and functions. One database can have multiple schemas (default: 'public'). In MySQL, 'schema' and 'database' are synonymous. The term is used loosely to mean 'the structure of your tables.'
- Should I use foreign key constraints?
- Yes for OLTP databases — they prevent orphaned records and enforce referential integrity at the database level. Some high-scale systems disable FK constraints for insert performance, enforcing referential integrity at the application level instead — a tradeoff requiring careful discipline.
- What is third normal form (3NF)?
- A table is in 3NF if: every non-key column depends on the primary key, the whole key, and nothing but the key. The classic violation: storing a customer's city and also their zip code, where city depends on zip (a transitive dependency). Splitting into a separate zip-code table resolves this.