Home > Database > Mysql Tutorial > How to Correctly Rename a Column in SQL Server 2008?

How to Correctly Rename a Column in SQL Server 2008?

DDD
Release: 2025-01-07 15:51:41
Original
924 people have browsed it

How to Correctly Rename a Column in SQL Server 2008?

Column renaming in SQL Server 2008

Question:

In SQL Server 2008, I tried to rename a column in a table using the following SQL statement:

ALTER TABLE table_name RENAME COLUMN old_name to new_name;
Copy after login

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.

The syntax for

sp_rename is as follows:

EXEC sp_RENAME 'TableName.OldColumnName', 'NewColumnName', 'COLUMN';
Copy after login

The correct SQL statement for your case would be:

EXEC sp_RENAME 'table_name.old_name', 'new_name', 'COLUMN';
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template