05.30.08
Query to Change Column Name in sql server
I have created an Table Test with wrong column name as EepId instead of EmpID, and now i want to change it to EmpID, the following is the query to get
create table Test
(
EepID int
)
insert into Test values(2)
Now I want EepID column to Change to EmpID. The following is the solution
EXEC sp_rename
@objname = ‘Test.EepID’,
@newname = ‘EmpID’,
@objtype = ‘COLUMN’
sunny pandit said,
April 28, 2009 at 7:17 am
But what to do when we need to change column name as well as its type ??
ushant said,
September 14, 2009 at 11:43 am
is there no any other method to solve this query.
amit sharma said,
September 25, 2009 at 6:23 am
sir ,
may i know how to change a column name in sql 2000. I tried
–alter table t1 alter column t1_phno varchar(10) to phno varchar(10)– but it is not working ..
can anybody help .
thanks a lot..
amit sharma
amit sharma said,
September 25, 2009 at 8:24 am
yes i found it and it is for how to change the column name in sql……
exec sp_rename ‘t1.[t1_name]‘,’name’,'column’
where t1 is the table name ,and t1_name is the column name which is to be changed, and “name” it is name after change…………..
thanks and enjoy..
Yas said,
October 20, 2009 at 8:16 am
Thanks it really helped
Anuj said,
November 9, 2009 at 9:52 am
exec sp_rename ‘t1.[t1_name]‘,’name’,’column’