Home » RDBMS Server » Server Administration » can we rename a column in 9i ?
can we rename a column in 9i ? [message #53064] Tue, 27 August 2002 05:35 Go to next message
Sudheer Varier
Messages: 1
Registered: August 2002
Junior Member
I would like to know whether 9i allows renaming
columns if so how?
Re: can we rename a column in 9i ? [message #53070 is a reply to message #53064] Tue, 27 August 2002 07:52 Go to previous messageGo to next message
André ALIMBA
Messages: 16
Registered: April 2002
Junior Member
You cannot rename directly a column name by using RENAME command.

So, you have 2 solutions :

SOLUTION I
==========
1) add a new column with the new name you want (same type, same caracteristics than the old column)
- alter table nom_table add (new_col_name varachar2(5));
2) Put the value of old column in the new column
- update nom_table set new_col_name = old_col_name;
3) Drop the old column
- alter table nom_table drop column old_col_name;

SOLUTION 2
==========
1)Create a new table having the characteristics from the old
- CREATE TABLE new_name_table (new_col_name, colname2, colname3)AS SELECT old_col_name, colname2, colname3 FROM old_name_table;

2) Drop the old table :
- DROP TABLE old_name_table;

3) Rename new table with the name from the old table
- RENAME new_name_table TO old_name_table;

ATTENTION :
=========
old_col_name must no reference in others tables (referential constraints integrity)
Re: can we rename a column in 9i ? [message #53073 is a reply to message #53064] Tue, 27 August 2002 08:12 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
in 9iR2 you can rename a column. chances are you aren't using that though.
Previous Topic: USER rights & packages
Next Topic: Re: Ora-01502
Goto Forum:
  


Current Time: Thu Sep 19 11:49:06 CDT 2024