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.

Go Back  dBforums > Database Server Software > MySQL > quick question...answer you know off top of your head

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-26-08, 04:15
Leafgreen Leafgreen is offline
Registered User
 
Join Date: Apr 2008
Posts: 7
Talking 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.
Reply With Quote
  #2 (permalink)  
Old 05-26-08, 06:54
r937 r937 is offline
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
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 05-26-08, 15:09
Leafgreen Leafgreen is offline
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?
Reply With Quote
  #4 (permalink)  
Old 05-26-08, 16:19
r937 r937 is offline
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 */
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #5 (permalink)  
Old 05-26-08, 17:35
georgev georgev is offline
SQL Apprentice
 
Join Date: Jan 2007
Location: hiding
Posts: 8,131
But why..?
__________________
George
You only stop learning when you stop asking questions.
Reply With Quote
  #6 (permalink)  
Old 05-26-08, 17:44
r937 r937 is offline
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.
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #7 (permalink)  
Old 05-26-08, 19:07
georgev georgev is offline
SQL Apprentice
 
Join Date: Jan 2007
Location: hiding
Posts: 8,131
"u" ?
EDIT: Mr
__________________
George
You only stop learning when you stop asking questions.
Reply With Quote
  #8 (permalink)  
Old 05-26-08, 19:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,537
george, google this as a phrase: "let me show you it"
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #9 (permalink)  
Old 05-26-08, 19:49
georgev georgev is offline
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.
Reply With Quote
  #10 (permalink)  
Old 05-26-08, 19:55
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,537
that is right, the http://icanhascheezburger.com lolcats
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #11 (permalink)  
Old 05-27-08, 14:45
Leafgreen Leafgreen is offline
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.
Reply With Quote
  #12 (permalink)  
Old 05-28-08, 18:12
georgev georgev is offline
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On