Here’s how I do it:
- Table names are lower case, uses underscores to separate words, and are singular (e.g.
- I generally (not always) have a auto increment PK. I use the following convention:
- When a table contains a column that is a foreign key, I just copy the column name of that key from whatever table it came from. For example, say table
foo_barhas the FK
foo_idis the PK of
- When defining FKs to enforce referential integrity, I use the following:
tablename_fk_columnname(e.g. furthering example 3, it would be
foo_bar_foo_id). Since this is a table name/column name combination, it is guaranteed to be unique within the database.
- I order the columns like this: PKs, FKs, then the rest of columns alphabetically
Is there a better, more standard way to do this?