#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    C:\Wonderland
    Posts
    15
    Rep Power
    0

    Talking In PHPMyAdmin, how can I duplicate a row in a table?


    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.

    What would you do in this scenario?
    TIA!
    Leafgreen
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,179
    Rep Power
    4279
    i would do it like this

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    C:\Wonderland
    Posts
    15
    Rep Power
    0
    Rudy, wtf. I posted here because I wanted someone else's opinion. Also, George never answered my question about his question, which seemed to suggest that my question here was basically flawed.
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,179
    Rep Power
    4279
    so i guess you didn't like my suggestion?

    what was wrong with it?

    hey at least it works

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,448
    Rep Power
    1751
    If it helps any it's the way I'd do it too.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    C:\Wonderland
    Posts
    15
    Rep Power
    0
    Rudy & Simon, I wouldn't use this solution because it will take so much time to copy all of the column labels. It would be simpler just to use my Windows clipboard extender Clipcache, copy all the cell values, insert new row, and paste in the duplicate values. Actually, that's the way I do it now.
  12. #7
  13. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,179
    Rep Power
    4279
    Originally Posted by leafgreen
    ...it will take so much time to copy all of the column labels.
    when i do it, i use CTRL-C to copy them all and CTRL_V to paste them into my text editor, then use a quick search/replace to insert the commas between them

    takes about twelve seconds altogether

    i always use a text editor when working with SQL -- typing SQL directly into the SQL window is too much like work
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Winnipeg, Canada
    Posts
    50
    Rep Power
    12

    Yes, you can


    Go in to edit the row you want to copy. Make all the changes as they should appear in the new record. Then, instead of "save", select "insert as new record" and hit GO.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    Thank You teezeCrost !

    I spent about 2 hours trying to figure this out - importing and exporting the sql data, etc.

    Your solution was right in front of me all along. I just tried it and it worked great !


IMN logo majestic logo threadwatch logo seochat tools logo