Possible Duplicate:
Primary key/foreign Key naming convention
What is the naming convention for Primary Key column in Db Tables?
For instance: PK_Country or CountryId or ID or PrimaryKey or.. ?
Possible Duplicate:
Primary key/foreign Key naming convention
What is the naming convention for Primary Key column in Db Tables?
For instance: PK_Country or CountryId or ID or PrimaryKey or.. ?
I like the Ruby on Rails conventions:
id
_id
. Example:
country_id
is a foreign key that corresponds to a record from the countries
tableColumns should be named based on the data elements that they represent, not based on what constraints apply to them. A primary key column should be named in the same way you name any other column. The ISO 11179 standard has some useful guidelines for naming data elements.
If the table is called Test
I would call the PK column TestID
.
That is pretty much up to the designer of the db. When I do it I make the field name of the primary key: id and field name of foreign keys: tablenameId
I always try to start primary keys with PK and foriegn keys with FK. Also, when naming foriegn keys, I try to include the table names and column names in the name of the foriegn key: FK_Questions-test-id_Tests-seq-num would be a foriegn key from table questions to table tests where questinos.test_id = tests.seq_num. i think it helps to name them that way for when you are glancing at your keys.
There really is not a defined standard; rather, you should develop your own convention and make sure that every primary key you define is consistent with that convention.