Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Column Name Change

 
   Database Forums (Home) -> Oracle RSS
Next:  Server Database  
Author Message
Jeff B

External


Since: Sep 17, 2007
Posts: 10



(Msg. 1) Posted: Sun Dec 02, 2007 7:59 am
Post subject: Column Name Change
Archived from groups: comp>databases>oracle>misc (more info?)

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

 >> Stay informed about: Column Name Change 
Back to top
Login to vote
Charles Hooper

External


Since: Apr 18, 2007
Posts: 92



(Msg. 2) Posted: Sun Dec 02, 2007 7:59 am
Post subject: Re: Column Name Change [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Dec 2, 7:07 am, "Jeff B" wrote:
> 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/cd/B10501_01/server.920/a96540/stat...nts_32a

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.

 >> Stay informed about: Column Name Change 
Back to top
Login to vote
Jeff B

External


Since: Sep 17, 2007
Posts: 10



(Msg. 3) Posted: Sun Dec 02, 2007 9:59 am
Post subject: Re: Column Name Change [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" wrote in message

> 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
 >> Stay informed about: Column Name Change 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How to change default tablespace of self - Hi Im trying to create tables of one "create_tables" script file in one tablespace and that of another "create_tables" script in some other tablespace. At the same time i do not want to hardcode the tablespace clause in the "cre...

Change text in a table - Hello, I want to replace a portion of a string value in columns in a table. Lets say I have a table called TABLE_TEST with something like this: value....................string value 1............................string1\string3..

RMAN Backup: Change Archivelog all crosscheck - Hi, i have a question about RMAN (RMAN Backup with catalog and a backup software). What does CHANGE ARCHIVELOG ALL CROSSCHECK; mean? It checks if all archived redo logs which are registered in the RMAN DB still exists in the backup, that's right? S...

Oracle Spatial: Change coordinates of SDO_GEOMETRY objects - Hallo, does any know a link or has a sample for me how to change the ordinate list of a SDO_GEOMETRY? With SDO_UTIL.GETVERTICES it is possible to get the coordinates. Is there a setter function too? SETVERTICES does not exist. I only need to change the...

SQL Column Heading - Hi guys, When we execute a select stmt in sqlplus we don't get the column headings full , it is shown according to the data in that column. So, i want to display the column headings in full as it was mentioned , while creating the table. Can tell by..
   Database Forums (Home) -> Oracle All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]