Naming standardization scripts
Enforcing or applying Naming Convention in a database
Throughout my database career, I have always been annoyed to work with databases, where object naming convention was city in ancient Greece. It seems, that every DBA or developer has their own opinion about, how to name objects in their databases, or have no interests in their names at all. In my opinion a naming convention should be established for a database and all developers should use it consistently. A naming convention should assist a person to understand what the object covers, and not require people to script out objects, when they need to understand what the object consist of.
I love it, when I read query plans, and index names are enough to understand, what the index consists of. Or reading foreign key names, and easily be apple to figure out, which tables and columns are involved in the relationship
I not going to lecture about a certain naming convention, which I think is the best, because that will be futile. I don’t want to start a religious war, amongst database developers and DBA’s. Instead I have come to the conclusion, that what is needed is an easy and flexible way of enforcing a user designed naming convention, throughout a database. I have generated a couple of stored procedures, which can help renaming existing objects in a database or assist with naming new object.
I have created some stored procedures, which I believe is very flexible and should suite most people needs. I believe that it is only certain objects in a SQL Server database, which benefit from an automated way of applying a naming convention. It still makes sense for other SQL objects to have a naming convention, but it can be very difficult to automate, and it should be enforce manually.
The SQL objects, which I think are great for enforcing a naming convention automatically are Check Constraints, Default Constrains, Foreign Key Constraints, Indexes and Primary and Unique Key constraints
The following stored procedures can be used for applying a custom naming convention
dbautils. spFixIndexNaming:
This stored procedure covers renaming of Indexes, Xml indexes, Spatial Indexes, Filtered indexes, Primary keys and Unique Keys
dbautils.spFixColumnCheckNaming:
This stored procedure handles renaming of column check constraints. Table constraints are not supported, as they are not ideal for automated renaming. The stored procedure is still in development
dbautils.spFixColumnDefaultNaming:
This stored procedure handles renaming of column default constraints. The stored procedure is still in development
dbautils.spFixForeignKeyNaming:
This stored procedure handles renaming of foreign key constraints. The stored procedure is still in development
The scripts are available under the following restrictions.
THIS CODE AND INFORMATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE. YOU MAY USE AND MODIFY THIS CODE FREELY, BUT
YOU MAY NOT REPUBLISH IT AS YOUR WORK