Home » SQL & PL/SQL » SQL & PL/SQL » create new record based on old...
create new record based on old... [message #19171] Mon, 04 March 2002 06:08 Go to next message
Jared
Messages: 10
Registered: June 2001
Junior Member
I need to create a new record in a table with all the same data as an existing record (except for a new unique primary key value). Can I do this with one line in SQL? Thanks in advance!

Jared
Re: create new record based on old... [message #19172 is a reply to message #19171] Mon, 04 March 2002 06:27 Go to previous messageGo to next message
pratap kumar tripathy
Messages: 660
Registered: January 2002
Senior Member
yep u can.

insert into your table_name
select new_primary_key,column_list......
where ......restriction goes here......
Re: create new record based on old... [message #19175 is a reply to message #19171] Mon, 04 March 2002 06:50 Go to previous messageGo to next message
Jared
Messages: 10
Registered: June 2001
Junior Member
Is there a way to do this without listing out all the column names??

Like,

insert into table1 AS SELECT * from table1 where ID = X

and then somehow change the key within this statement?
new primary key [message #19178 is a reply to message #19171] Mon, 04 March 2002 07:14 Go to previous messageGo to next message
Jared
Messages: 10
Registered: June 2001
Junior Member
How can I get a new primary key through SQL?

Jared
Re: see this URL [message #19186 is a reply to message #19175] Mon, 04 March 2002 14:58 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
http://asktom.oracle.com/pls/ask/f?p=4950:8:558600::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:2941199851647,
Previous Topic: extract some letters from a string
Next Topic: TKPROF analysis
Goto Forum:
  


Current Time: Tue Apr 23 05:37:02 CDT 2024