How to name keys with MSSQL

  • These are my conventions, they are not mandatory.
  • Many people have their own conventions, great! keep them.
  • I do not intend to impose my conventions on them, just here are mine.

Key naming conventions

  • The primary key starts with pk_ then followed by the name of the table. For example: the primary of the tables trans02 is pk_trans02. The primary key of the NADs [name and address table] is pk_nads.
  • The foreigh key starts with fk_ then followed by the destination table + destination column. For example: The foreign key of table trans02 on column code to table codtabs [a code table] column is fk_codtabs_code (destination table + destination column).
  • The simple key starts with k_ then followed by the actual table + actual column name. For example: The key of table trans02 on column desc is k_trans02_description (table + column).

Applies to:

  • Microsoft SQL Server 2000
  • Microsoft SQL Server 2005
  • Microsoft SQL Server 2008
  • All SQL Servers