Rename a column using SQL

J

JornyO

I am trying to rename a colum using an SQL statement run in a macro using the
RunSQL action. Some forums have told me to use the following:

ALTER TABLE [CurrentTable] RENAME COLUMN [OldName] TO [NewName];

When I try to run this I get the following message: "Syntax Error in the
ALTER TABLE statement". What am I doing wrong? It seems pretty simple to
me, and many other forums have offered this advice for doing this.
 
S

Sylvain Lafontaine

Maybe I'm wrong but I'm not sure if SQL-Server offerts support for the ALTER
TABLE RENAME COLUMN statement. Instead, you should use the stored procedure
sp_rename:

sp_rename 'CurrentTable.OldName', 'NewName', 'COLUMN'

For the RunSQL command, I don't know what would be the exact syntax and it's
also possible that you will have to add the EXEC command at the beginning:

Exec sp_rename 'CurrentTable.OldName', 'NewName', 'COLUMN'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top