Search code examples
sql-serversp-rename

Renaming a column: Incorrect syntax near 'SP_RENAME'.?


ALTER TABLE [TEMP]
SP_RENAME '[TEMP].[Day]', 'GT', 'COLUMN'

I am trying to rename Day to GT and am getting the error

Incorrect syntax near 'SP_RENAME'

SQL Server Management Studio says the error is on SP_RENAME

NOTE: I'm open to other options besides sp_rename


Solution

  • SP_RENAME is not part of the ALTER TABLE statement. It is a system stored procedure and therefore it should be invoked using the EXEC/EXECUTE statement, like this:

    exec SP_RENAME '[TEMP].[Day]', 'GT', 'COLUMN'
    

    (without the alter table temp bit)