| |
Welcome to the dBforums forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact contact support.
If you prefer not to see double-underlined words and corresponding ads, place your cursor here for ContentLink opt out.
|
 |

05-26-08, 04:15
|
|
Registered User
|
|
Join Date: Apr 2008
Posts: 7
|
|
In PHPMyAdmin, how to duplicate a record in a table?
|
In PHPMyAdmin, how can I duplicate a record in a table?
|
Last edited by Leafgreen : 05-26-08 at 04:43.
|

05-26-08, 06:54
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,537
|
|
off the top of my head, you can't
a table should have a primary key, and a primary key is by definition unique
therefore you can't duplicate an entire "record"
(note: in relational databases, they are rows, not records)
if you want some other variant of duplication, you will have to give us some more specifics
|
|

05-26-08, 15:09
|
|
Registered User
|
|
Join Date: Apr 2008
Posts: 7
|
|
|
Hi r937 and Thank you for your reply. I see what you mean about the primary key. Ok, then if you wanted to duplicate all the information in a row, and make a new row except with an incremented value for the primary key, how would you do that?
|
|

05-26-08, 16:19
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,537
|
|
i would do it like this:
Code:
INSERT
INTO daTable
( list all columns except auto_increment )
SELECT list all columns except auto_increment
FROM daTable
WHERE id = nnn /* where nnn is the id of the row i want to copy */
|
|

05-26-08, 17:35
|
|
SQL Apprentice
|
|
Join Date: Jan 2007
Location: hiding
Posts: 8,131
|
|
|
__________________
George
You only stop learning when you stop asking questions.
|
|

05-26-08, 17:44
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,537
|
|
reasons why: let me show u them
1. because the original poster asked for it
2. see 1.
|
|

05-26-08, 19:07
|
|
SQL Apprentice
|
|
Join Date: Jan 2007
Location: hiding
Posts: 8,131
|
|
"u" ?
EDIT: Mr 
__________________
George
You only stop learning when you stop asking questions.
|
|

05-26-08, 19:39
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,537
|
|
george, google this as a phrase: "let me show you it"
|
|

05-26-08, 19:49
|
|
SQL Apprentice
|
|
Join Date: Jan 2007
Location: hiding
Posts: 8,131
|
|
...something to do with roflcats...?
I still don't geddit 
__________________
George
You only stop learning when you stop asking questions.
|
|

05-26-08, 19:55
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,537
|
|
|
|

05-27-08, 14:45
|
|
Registered User
|
|
Join Date: Apr 2008
Posts: 7
|
|
George: I guess I am missing something based on your response, "But why?" My frequent scenario is that I have a table with about 30 columns, and each cell has a significant amount of data. But sometimes, I need to add a row with very similar data as an existing row. So the quickest way to add a row with mostly the same data is to
1. duplicate it with an incremental primary key, then
2. make the minor change(s) in the new row's cells as I wish.
This is much quicker than adding a new, empty row and then re-typing or copying and pasting into each of the 30 cells. Geddit? What would you do in this scenario?
Rudy: thanks for your answer.
|
Last edited by Leafgreen : 05-28-08 at 15:02.
|

05-28-08, 18:12
|
|
SQL Apprentice
|
|
Join Date: Jan 2007
Location: hiding
Posts: 8,131
|
|
Dear me, appear to have missed this here thread.
I'm glad you've come up with a justification for doing this - my "but why?" was aimed at finding this out exactly!
Call my a cynic, but generally when people ask this it is because their design is flawed - 99% of the time duplicate data is redundant data.
And anyhow, I would still approach it wish a single insert which included the minor changes, rather than running >1 query to produce the record.
If you simply want to duplicate with the new seed - Rudy's response will give you that.
P.S. Rudy, thanks for the PM - it did make me chuckle 
__________________
George
You only stop learning when you stop asking questions.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|