Can we Change a Column Name
Suppose I have a table names student having a column named as "> roll_no". now I have to change its name by " registration_no ". Can we do this?
Renaming a column of an Oracle is possible.
ALTER TABLE ..table_name .. RENAME COLUMN ..old_column_name.. to ..new_column_name..
Column rename feature is supported by oracle 9.x onwards
Thus in caes you are using oracle 9.x or later versions use following query
ALTER TABLE tablename RENAME COLUMN oldcolumn TO newcolumn;
In case you are usinf oracle prior to 9 use following options.
Other workarounds:
1. -- Use a view with correct column names...
rename t1 to t1_base;
create view t1 ..column list with new name.. as select * from t1_base;
2. -- Recreate the table with correct column names...
create table t2 ..column list with new name.. 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;
You can rename a column in oracle.
try this,
ALTER TABLE tablename RENAME COLUMN oldcolumn TO newcolumn;
0 comments:
Post a Comment