Part 150: The SQL Master Blueprint: 25 Principal Database Rules
Congratulations on reaching the final part of this comprehensive 150-Part SQL Language Tutorial series! In this capstone, we synthesize our entire curriculum into 25 core rules for principal-level database engineering.
The 25 Golden Rules of Relational Database Engineering
- Explicit Columns: Never use
SELECT *in production queries. - Surrogate Keys with Business UUIDs: Pair internal auto-increment primary keys with exposed UUIDs.
- Always Index Foreign Keys: Prevents full table locks on cascading updates and joins.
- Enforce Referential Integrity: Use foreign key constraints rather than hoping application code maintains relations.
- Decimals for Money: Never use
FLOATorDOUBLEfor financial amounts. - UTC Everywhere: Store audit timestamps as
TIMESTAMPTZin UTC. - Explicit Nullability: Declare
NOT NULLby default on all columns. - Keyset Pagination over Offset: Use
WHERE id < :last_idfor scalable pagination. - Beware the NOT IN + NULL Trap: Use
NOT EXISTSinstead ofNOT IN. - Parentheses for Logic: Wrap mixed
ANDandORconditions in explicit parentheses. - UNION ALL by Default: Use
UNION ALLunless duplicate removal is strictly required. - CTEs for Readability: Replace deeply nested subqueries with structured CTEs.
- Keep Window Functions in Select: Leverage
OVER (PARTITION BY ...)for analytical reporting without row collapse. - Avoid Leading Wildcards:
LIKE '%query'cannot use standard B-Tree indexes. - SARGable Filters: Never wrap indexed columns in functions inside
WHEREclauses. - Profile with EXPLAIN ANALYZE: Verify execution plans before guessing optimizations.
- Covering Indexes for Hot Paths: Use
INCLUDEcolumns to enable Index-Only Scans. - Normalize to 3NF First: Normalize for integrity, and denormalize only after profiling proven bottlenecks.
- Drop Unused Indexes: Eliminate indexes with 0 scans to restore write performance.
- Keep Transactions Short: Minimize lock holding times and lock escalation risks.
- Deterministic Lock Ordering: Acquire locks in alphabetical/ID order to prevent deadlocks.
- Always Parameterize Queries: Defeat SQL Injection 100% of the time.
- Partition Massive Datasets: Use declarative range partitioning on time-series logs.
- Multi-Tenant Row-Level Security: Enforce tenant data isolation with database RLS policies.
- Automate Continuous Backups: Verify Point-in-Time Recovery (PITR) procedures regularly.
Conclusion
You have mastered SQL from foundational DQL to advanced analytical window functions, internal engine architecture, indexing mechanics, and enterprise database administration. May your queries run in milliseconds!

