dbTalk Databases Forums  

Column Name Change

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Column Name Change in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jeff B
 
Posts: n/a

Default Column Name Change - 12-02-2007 , 06:07 AM






Good Morning,

Is it possible to change a column name of a table after the table has been
created? I have a table called Members that have FirstName, LastName
columns. The problem I have is the information that got put into the table
had the names reversed, so now all the first names are in the LastNamr
column and all of the last names are in the FirstName columns. I tried
Delete Members but I recieved an error about a value being shared, I found
on one website Replace Column column_name To new_name but this did not work
as I could not figure out how to reference which table I wanted to make that
change in.

Just kind of stuck at the moment, seems easiest thing would be just to
cjange the column headings to match the data but I can not find a Modify or
AlterTable command to do this?

Thanks for the help,

Jeff


Reply With Quote
  #2  
Old   
Jeff B
 
Posts: n/a

Default Re: Column Name Change - 12-02-2007 , 07:51 AM






Ok never mind I found the answer, It was a combination of these things.

What I got to work was:
SQL> alter table members
2 rename column LastName to FirstNames;

Table altered.

SQL> alter table members
2 rename column FirstName to LastName;

Table altered.

SQL> alter table members
2 rename column FirstNames to FirstName;

Table altered.

Just wanted to pass along what I found.

Jeff

"Jeff B" <jeffby (AT) KnoSpam (DOT) tds.net> wrote

Quote:
Good Morning,

Is it possible to change a column name of a table after the table has been
created? I have a table called Members that have FirstName, LastName
columns. The problem I have is the information that got put into the
table had the names reversed, so now all the first names are in the
LastNamr column and all of the last names are in the FirstName columns. I
tried Delete Members but I recieved an error about a value being shared,
I found on one website Replace Column column_name To new_name but this
did not work as I could not figure out how to reference which table I
wanted to make that change in.

Just kind of stuck at the moment, seems easiest thing would be just to
cjange the column headings to match the data but I can not find a Modify
or AlterTable command to do this?

Thanks for the help,

Jeff


Reply With Quote
  #3  
Old   
Charles Hooper
 
Posts: n/a

Default Re: Column Name Change - 12-02-2007 , 08:04 AM



On Dec 2, 7:07 am, "Jeff B" <jef... (AT) KnoSpam (DOT) tds.net> wrote:
Quote:
Good Morning,

Is it possible to change a column name of a table after the table has been
created? I have a table called Members that have FirstName, LastName
columns. The problem I have is the information that got put into the table
had the names reversed, so now all the first names are in the LastNamr
column and all of the last names are in the FirstName columns. I tried
Delete Members but I recieved an error about a value being shared, I found
on one website Replace Column column_name To new_name but this did not work
as I could not figure out how to reference which table I wanted to make that
change in.

Just kind of stuck at the moment, seems easiest thing would be just to
cjange the column headings to match the data but I can not find a Modify or
AlterTable command to do this?

Thanks for the help,

Jeff
If you are running Oracle 9i R2 and above, there is a quick way to
rename a column. From a Google search on the terms: alter table
rename column oracle:
http://download-uk.oracle.com/docs/c...2a.htm#2103992

Another option is to rename the table, then use a CREATE TABLE AS
SELECT to create a new table with the old name that is based on the
column definitions (rename the columns using an alias in the select),
bringing along the data from the old table. You will then need to
recreate any triggers that were on the old table.

Another option is to update both colunms in the table at the same time
and set:
LASTNAME=FIRSTNAME,
FIRSTNAME=LASTNAME

A fourth option is to create a view based on the table with the column
names aliased to their correct meaning.

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.