Using ID for Primary Key Column Name is check Id # 7 in my SQL Server Assess open source project on GitHub. The project contains a stored procedure named sp_Develop that can be used by database developers, software developers and for performing database code (smell) assessment to adhere to SQL Server database development best practices.

For columns that are the primary key for a table and uniquely identify each record in the table, the name should be [TableName] + “Id” (e.g. On the Make table, the primary key column would be “MakeId”).

Though “MakeId” conveys no more information about the field than Make.Id and is a far wordier implementation, it is still preferable to “Id”.

Naming a primary key column “Id” is also “bad” when you query from several tables you will need to rename the “Id” columns so you can distinguish them in result set with aliases.

Using just “Id” can mask join issues that are not obvious at first sight.






Now you can see that MK.MakeId does not equal C.ColorId in the last table join below.






Interested in learning more? Visit the documentation website or the project directly on GitHub!