Credits:
Description
- Primary Key: PK_<TableName>
- ForeignKey: FK_<ParentTableName>_<ChildTableName>
Code
Standardise Primay Key Names:
|
Standardise Foreign Key Names:
|
Cool Tips > Data Formatting >
Data Formatting Standardise PK and FK NamesCredits:Author: Unknown
Date: 11 May 2010
DescriptionWhen creating primary or foreign keys using TSQL or the GUI, there is currently no way of enforcing a naming convention at creation time - the system automatically generates a name. A separate command must be run afterwards to rename the constraint.
Most ER Design tools offer the option of providing or enforcing a naming convention at design time, before scripts are generated and rolled out, but not every DBA shop can afford these often pricy additions to the arsenal.
I find it very helpful, not only on a personal level, but for development teams, to have a standard naming convention that allows easy and immediate understanding of the PK/FK relationship scope and direction
The following two scripts will generate TSQL commands for changing all PK and FK names in a database.
They are written to enforce the following standard:
but may be easily altered to whatever standard that you use.
CodeStandardise Primay Key Names:
Standardise Foreign Key Names:
|