469,579 Members | 1,161 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Copying a row

Hi everyone,

Is there any easy way to duplicate a row in a table with auto increment
column, that shouldn't of course be copied. I tried a query "NSERT INTO
table SELECT * FROM table" but it caused an error due to the auto
increment column. I succeeded with listing all required fields in the
query, but it's not very efficient way to do it (in my opinion) as when I
modify the table (add or remove columns), I should modify also all
queries.

Any help is appreciated.

Thanks,
Ville

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/my***********...ie.nctu.edu.tw

Jul 19 '05 #1
1 6169
guest
25
What do you think about this?

Create a duplicate table with the same structure. Sample: tableAux. And...

1) TRUNCATE TABLE tableAux

2) INSERT INTO tableAux SELECT * FROM table WHERE id=...

3) UPDATE tableAux SET id =...
// Could be (SELECT MAX(id) FROM table) + 1 or similar.
// You could update other fields to of course.

4) INSERT INTO table SELECT * FROM tableAux

Maybe isn't simple but i think isn't so bad at all, because you don't need to be worry about new added fields to the original table.

And nice password guest ;)
Jun 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Thomas Lotze | last post: by
3 posts views Thread by Robert Tarantino | last post: by
13 posts views Thread by franky.backeljauw | last post: by
22 posts views Thread by Matt | last post: by
reply views Thread by surya | last post: by
1 post views Thread by Mark Smith | last post: by
1 post views Thread by emilysmith10 | last post: by
1 post views Thread by RonLandreth | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.