Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using the below query to change the column name in a table.

SP_RENAME 'Student.StudentId', 'SID ', 'COLUMN'

Any alternate query to change the column name in a table.
Posted

As far as I know: No.

Note: You need to disable any constraints on the column first and modify them too to be active for the new column.

But, you could drop & create the table again with the new name of the column if that suits you more ;)
 
Share this answer
 
You can also change the name of a column via the Object Explorer or Table Designer in SSMS.

Here is the link to the microsoft documentation[^] on how to achieve this

[Edit - inspired by Nicholas Marty's solution]
When you are doing a select from your original table detailing each column by name change it to use Student.StudentId AS SID instead. Changing a column name from StudentId to SID doesn't really achieve much
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900