Skip to content
Advertisement

Update Primary Key Column Name in SQL

This code defines Category table in SQL:

I need to change [CategoryID] to [ID] i.e., change its name. How can this be accomplished?

Thanks in advance.

Advertisement

Answer

For versions SQL Server 2008 and above; you may execute the following stored procedure

exec sp_rename 'Categories.CategoryID', 'Id', 'COLUMN';

Reference SQL Docs

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement