Page 1 of 1

Duplicating Rows

Posted: Wed Jun 21, 2006 1:42 pm
by BigAbe
Is there any shortcut to automatically duplicate a row into the same table?

The only catch is that my PK is autoincrementing and I want to duplicate one row as a new row.

Thanks!

-- Abe --

Posted: Wed Jun 21, 2006 2:46 pm
by feyd

Posted: Thu Jun 22, 2006 1:30 pm
by BigAbe
Maybe I'm extremely lazy, but this sounds like a bit too much for one operation.

Is there any other way to just copy one row?

Posted: Thu Jun 22, 2006 1:36 pm
by Benjamin
It's actually not that difficult, and other then inserting a record, I don't see another method of doing it.

Posted: Thu Jun 22, 2006 1:41 pm
by BigAbe
astions wrote:It's actually not that difficult, and other then inserting a record, I don't see another method of doing it.
Fair enough - I guess I wish programming were simpler than it is.

Or maybe not... If that were so, I might be out of a job. 8)

Posted: Thu Jun 22, 2006 1:54 pm
by RobertGonzalez
If you don't mind me asking, what is the benefit to having duplicate data (less the PK) in a table?

Posted: Thu Jun 22, 2006 6:06 pm
by BigAbe
Everah wrote:If you don't mind me asking, what is the benefit to having duplicate data (less the PK) in a table?
Not so much a benefit, just an easier way to manage my data.

I'm in the finishing stages of building a full-on classified system for my university.

One of the parts is like a control panel, where users can view their currently running ads and previous ads. My system allows them to repost or delete ads with one click.

Because we want to keep a complete record of all ads being posted (not trying to be "big-brother", just CYA), when ads are deleted, we simply "deactivate" them versus actually deleting them.

So, when a user wants to repost their ad, we set the current ad to inactive, and repost the very same ad under a new row with the same exact information, just a different PK.

Does this make sense?

-- Abe --

Posted: Thu Jun 22, 2006 6:11 pm
by RobertGonzalez
Yeah. You might be able to achieve that with SELECT INTO, but I am not certain.