Columns renaming
-
Hi I need to create a stored procedure that changes the column name of a column in a datatable. Can someone help please? Thanks
You might want to give more information. As it is, changing the name of a column as you have it stated would be a one time operation. Alter Column [column_name]
"My interest is in the future because I'm going to spend the rest of my life there." - Charles F. Kettering
-
Hi I need to create a stored procedure that changes the column name of a column in a datatable. Can someone help please? Thanks
There is a stored procedure available in the System Stored Procedures in Sql Server. It is called sp_rename It accepts 3 parameters viz.
@objname nvarchar(1035), -- up to 4-part "old" name
@newname sysname, -- one-part new name
@objtype varchar(13) = null -- identifying the nameFor renaming a column, execute the following
EXEC sp_rename
@objname= 'TABLE_NAME.OLD_COLUMN_NAME',
@newname = 'NEW_COLUMN_NAME',
@objtype = 'COLUMN'N.B.~ For your reference, the @objecttype correspond to system tables which track of the folowing type: 'column' 'database' 'index' 'object' 'userdatatype' Hope this helps Vote me :)
Niladri Biswas