affiliate marketing Interview Qns: Can one rename a column in a table?

Monday, October 25, 2010

Can one rename a column in a table?

ALTER TABLE tablename RENAME COLUMN oldcolumn TO newcolumn;

Other workarounds

1. -- Use a view with correct column names...
rename t1 to t1_base;
create view t1 as select * from t1_base;

2. -- Recreate the table with correct column names...
create table t2 as select * from t1;
drop table t1;
rename t2 to t1;

3. -- Add a column with a new name and drop an old column...
alter table t1 add ( newcolame datatype );
update t1 set newcolname=oldcolname;
alter table t1 drop column oldcolname;

No comments:

Post a Comment