Tuesday, November 22, 2011

Changing column name and Datatype in Table in Sql

Title:How to Change column name and datatype in SQL server

This kind scenario will happen when we have to change the data base filed name or data type as per requirement.As per my application i need change the column type to Null.The SQL server provides a default stored procedure "sp_changename",which can make the things easier.Here i have used ALTER command To change the column name and data type in the table

Alter table TableName alter column ColumnName DataType NULL/NOT NULL
EXEC sp_changename        
@objname = ' TableName. OldColumnName’,
@newname = 'New ColumnName',
@objtype = 'COLUMN'

Alter table Organisation alter column name int null
EXEC sp_changename
@objname = 'Oraganisation.name',
@newname = 'name',
@objtype = 'COLUMN'
Post a Comment