Friday, March 9, 2012

How Alter column name of table?

Hi all,
I need modify one column name of my table.
How I can do this?
ThanksHi ReTF
Please always specify what version you are using.
In SQL Server 2005, the following example renames the TerritoryID column in
the SalesTerritory table to TerrID.
USE AdventureWorks;
GO
EXEC sp_rename 'Sales.SalesTerritory.TerritoryID', 'TerrID', 'COLUMN';
GO
The same syntax works in SQL Server 7 and 2000, but there is no
AdventureWorks database to try it on.
The key point when using the sp_rename procedure to rename a column is that
the first parameter includes both the table name and column name and can
also include the schema or owner name, and the second parameter is only the
new column name.
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"ReTF" <re.tf@.newsgroup.nospam> wrote in message
news:OgTprj8DGHA.336@.TK2MSFTNGP14.phx.gbl...
> Hi all,
> I need modify one column name of my table.
> How I can do this?
> Thanks
>|||You can use something like this:
EXEC sp_rename 'TableName.ColumnName', 'NewColumnName', 'COLUMN'
However, you should keep in mind that:
"Renaming an object such as a table or column will not automatically
rename references to that object. You must modify any objects that
reference the renamed object manually. For example, if you rename a
table column and that column is referenced in a trigger, you must
modify the trigger to reflect the new column name."
(quote from Books Online, topic "sp_rename")
Razvan

No comments:

Post a Comment