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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a duplicate record in a table with an identity field

Status
Not open for further replies.

hollander

Programmer
Oct 4, 2002
7
US
I've searched as many ways as I can and have not found a solution to this, so I'm guessing it can't be done (at least not easily). However, I figured I'd through it out there and see if I'm missing something obvious.

I'm looking for a SQL statement that will allow me to INSERT INTO tbl SELECT * FROM tbl WHERE id=1, where tbl has an identity field. Naturally, this statement produces an error because you can't insert a value into the identity field. I know I could list out every field twice, but I was hoping for a simpler solution.

Thanks.
 
Nope, there is no easiest way :)
Even if you SET IDENTITY_INSERT [Table name here] ON you must use field list.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Lazy and practical :)

Um... even without identity column, what will happen if source table has these columns:

foo, bar, blah

And target table has

bar, blah, foo

?

Btw. that drag&drop thingy from Query Analyzer (Object Browser) can make life easier in this case.

------
[small]<this is sig>
select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')
</this is sig>[/small]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top