Home >Database >Mysql Tutorial >How to Correctly Rename a Column in SQL Server 2008?
Question:
In SQL Server 2008, I tried to rename a column in a table using the following SQL statement:
<code class="language-sql">ALTER TABLE table_name RENAME COLUMN old_name to new_name;</code>
However, this statement doesn't seem to work. What's the problem?
Answer:
The SQL statement you provided is not the correct syntax for renaming columns in SQL Server 2008. To rename columns in SQL Server 2008, you need to use the sp_rename
stored procedure.
sp_rename
is as follows:
<code class="language-sql">EXEC sp_RENAME 'TableName.OldColumnName', 'NewColumnName', 'COLUMN';</code>
The correct SQL statement for your case would be:
<code class="language-sql">EXEC sp_RENAME 'table_name.old_name', 'new_name', 'COLUMN';</code>
Remember to enclose your values in single quotes.
More resources:
The above is the detailed content of How to Correctly Rename a Column in SQL Server 2008?. For more information, please follow other related articles on the PHP Chinese website!