Rename Column SQL Server 2008

Rename column SQL Server 2008

Use sp_rename

EXEC sp_RENAME 'TableName.OldColumnName' , 'NewColumnName', 'COLUMN'

See: SQL SERVER – How to Rename a Column Name or Table Name

Documentation: sp_rename (Transact-SQL)

For your case it would be:

EXEC sp_RENAME 'table_name.old_name', 'new_name', 'COLUMN'

Remember to use single quotes to enclose your values.

Change column name in SQL Server 2008

You need to use the sp_rename command, or use Management Studio to do it visually - make sure you do it at a quiet period, and make sure it has been done in pre-production first with testing!

Incidentally I would keep away from A/C - the slash sign is special meaning division.

The documentation for sp_rename is here, example B is most appropriate.
http://msdn.microsoft.com/en-us/library/ms188351.aspx

how to rename column name with T-SQL

I don't really understand how your table is set up - ie. the table name, the column name etc - so this is an example of how the proc works for column renames:

If I had a table like this:

CREATE TABLE [dbo].[Company](
[ID] [int],
[CompanyName] [varchar](20)
)

and wanted to change the [CompanyName] column, this is the command:

EXEC sys.sp_rename 
@objname = N'dbo.Company.CompanyName',
@newname = 'Name',
@objtype = 'COLUMN'

I suspect that your first argument is not correct.

From the documentation (sp_rename (Transact-SQL))

If the object to be renamed is a column in a table, object_name must be in the form table.column or schema.table.column. If the object to be renamed is an index, object_name must be in the form table.index or schema.table.index

Sql server rename a column

Just a reminder. Renaming columns is dangerous, because it might break scripts.

sp_rename 'MYDB.FOO', 'BAR', 'COLUMN'; 

Rename Column name in sql server 2008

Matrix.Sr.No means the No column in the Sr table of the Matrix schema in the current database. Try escaping the name:

sp_RENAME 'Matrix.[Sr.No.]','ID','COLUMN';

Rename column in SQL Server


EXEC sp_rename 'Categories.Active', 'CategoriesActive', 'COLUMN'

How to Rename Column name using DDL Statement in SQL

Execute this,

sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'

How do you rename columns using a Visual Studio Database Project?

After looking into this more it seems the refactoring feature is available in the Premium and Ultimate versions of Visual Studio 2010 and not in the Professional version.



Related Topics



Leave a reply



Submit