How to simply rename a column

Dom 776 Reputation points
2023-03-28T21:04:44.8866667+00:00

I thought the simple way to rename a column in SQL server was

ALTER TABLE TableName

RENAME COLUMN OldColumnName TO NewColumnName;

This results in

Msg 102, Level 15, State 1, Line 2

Incorrect syntax near 'RENAME'.

Did something change or am I doing something wrong? I ended up just going into Design... on the table and simply typed over the name, but I thought this was not the "programmer's" way, lol.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,681 questions
0 comments No comments
{count} votes

Accepted answer
  1. Naomi Nosonovsky 7,856 Reputation points
    2023-03-28T21:23:39.1+00:00

    Try using sp_rename procedure, e.g.

    EXEC sp_RENAME 'dbo.test.oldColumn', 'newColumn', 'COLUMN'

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.