Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I copy a record into the same table, but with a different PK

Status
Not open for further replies.

TeriCoombes

Technical User
Aug 26, 2004
22
US
I am at a loss as to how to create this stored procedure. I am basically trying to copy a record in my table and insert it into the same table, but with a different primary key. Can this be done?
 
Teri, a little more detail might help (probably will get you more responses as well).

Can you provide a small example of what you are trying to do? What parameters will be passed into the stored proc to determine the row to be copied?

How is your PK determined? Is it an identity, or are you managing it? Let us know,

Thanks,
Patrick
 
to do what you want you would normally use a

insert into tbl (field1, field2, ..., fieldn)
select new_pk_value, field2, ..., fieldn from tbl
where my_old_pk = xxx.

If it is a identity column then you just omit the pk from both the insert and select column list.


Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top