sql-conventions
Installation
SKILL.md
SQL Conventions
These are defaults for new schema decisions. Preserve established schema contracts and choose types, keys, and indexes for the database and business requirements; do not migrate existing data solely to match these preferences.
Naming Conventions
- Table names: Plural nouns, snake_case (
users,order_items) - Column names: snake_case (
created_at,user_id) - Index names: Follow the ORM/framework default. When naming manually, use
idx_{table}_{columns}for regular indexes,uq_{table}_{columns}for unique indexes - Foreign key columns:
{referenced_table_singular}_id(e.g.,user_id). When multiple columns reference the same table, use semantic names (e.g.,sender_id,receiver_idinstead ofuser_id_1,user_id_2)
Primary Key Strategy
Use auto-increment integer (SERIAL / BIGSERIAL / AUTO_INCREMENT) as the default primary key. It's simple, compact, and index-friendly.
When a public-facing, non-sequential identifier is needed, prefer a separate external_id / public_id alongside an existing integer PK. Distributed ID generation or an established UUID key may justify a different choice. Non-sequential IDs do not replace authorization.