5
Need to make a copy of a table in Mysql for a simulation, is there any function for it? How could I do that?
5
Need to make a copy of a table in Mysql for a simulation, is there any function for it? How could I do that?
6
If you want to create a new table based on an existing one, there is a very simple way to do:
CREATE TABLE nova_tabela SELECT * FROM tabela_a_copiar
There are some remarks about the use of this. I explained this in this question:
How to pass data from one table to another SQL
In order to copy auto_increment
, primary keys
and related, we have to use the command CREATE table LIKE
See how you’d look in this case:
CREATE TABLE nova_tabela LIKE tabela_a_copiar;
INSERT INTO nova_tabela SELECT * FROM tabela_a_copiar;
@Kaduamaral, thank you so much for collaborating with the answer! did not know the Sqlfiddle
You’re welcome Wallace, I was going to answer, but when I came back from the Sqlfiddle you had already answered, so I just added. ;)
Wallace, I noticed that this modeling does not make the auto_increment field as in the original table: http://sqlfiddle.com/#! 9/ca482/2 Know how to get around this?
Take a look at this SQLFIDDLE. I used the ALTER TABLE
next :)
@Kaduamaral, after a long time, I discovered a way, without having to give the ALTER TABLE
. See the update.
True, Wallace, fine. You can’t vote again, or you would. rsrs :P
What matters is information. It will help us a lot
Browser other questions tagged mysql
You are not signed in. Login or sign up in order to post.
Use the trial version of Navicat, then CTRL+C CTRL+V in the table... E F2 to rename it...:v
– KaduAmaral
I need a Mysql statement to do this. This will happen within a system
– Vynstus