Rename a column using SQL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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'
 
Back
Top