Standardise PK and FK Names
SQL Server 2000: Tested
SQL Server 2005: Tested
SQL Server 2008: Tested
SQL Server 2008R2: Tested
SQL Server 2012: Not Tested
Date: 11 May 2010
When 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:
Primary Key: PK_<TableName>
but may be easily altered to whatever standard that you use.
Standardise Primay Key Names:
Standardise Foreign Key Names: