这里我如何做:
- Table names are lower case, uses underscores to separate words, and are singular (e.g.
foo
,foo_bar
, etc. - I generally (not always) have a auto increment PK. I use the following convention:
tablename_id
(e.g.foo_id
,foo_bar_id
, etc.). - 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_bar
has the FKfoo_id
(wherefoo_id
is the PK offoo
). - When defining FKs to enforce referential integrity, I use the following:
tablename_fk_columnname
(e.g. furthering example 3, it would befoo_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
是否有更好、更标准的方法这样做?