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

How to Rename Columns in SQL Server 2008 Using `sp_rename`?

DDD
Release: 2025-01-07 16:06:09
Original
413 people have browsed it

How to Rename Columns in SQL Server 2008 Using `sp_rename`?

Rename columns in SQL Server 2008 using Navicat

In SQL Server 2008, using a simple ALTER TABLE statement to modify column names may not produce the expected results. To overcome this problem, we use the sp_rename system stored procedure.

sp_rename stored procedure for column renaming

The syntax of sp_rename when renaming a column is as follows:

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

Among them:

  • TableName: The table name containing the column to be renamed.
  • OldColumnName: The original name of the column.
  • NewColumnName: The desired new name for the column.

Code Example

For your scenario, the following code will rename the old_name column in table table_name to new_name:

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

Additional Notes

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

source:php.cn
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