Home >Database >Mysql Tutorial >How to Rename Columns in SQL Server 2008?

How to Rename Columns in SQL Server 2008?

Susan Sarandon
Susan SarandonOriginal
2025-01-07 16:07:40197browse

How to Rename Columns in SQL Server 2008?

SQL Server 2008: Efficient Column Renaming

In SQL Server 2008, the standard ALTER TABLE command for renaming columns may not function as expected. The recommended approach is to utilize the sp_rename stored procedure.

Here's the correct syntax:

<code class="language-sql">EXEC sp_RENAME 'TableName.OldColumnName', 'NewColumnName', 'COLUMN';</code>

For instance, to change "old_name" to "new_name" in the table "table_name":

<code class="language-sql">EXEC sp_RENAME 'table_name.old_name', 'new_name', 'COLUMN';</code>

Ensure all names are enclosed in single quotes. Consult the official Transact-SQL documentation for sp_rename for comprehensive details and further assistance.

The above is the detailed content of How to Rename Columns in SQL Server 2008?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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