Copiar tabla sin copiar datos
CREATE TABLE foo SELECT * FROM bar
Copia la tabla foo
y la duplica como una nueva tabla llamada bar
.
¿Cómo puedo copiar el esquema de foo
a una nueva tabla llamada bar
sin copiar los datos así?
104
3 answers
Intenta:
CREATE TABLE foo SELECT * FROM bar LIMIT 0
O:
CREATE TABLE foo SELECT * FROM bar WHERE 1=0
95
Author: Andomar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-12-02 17:28:39
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-12-02 17:28:39
Intenta
CREATE TABLE foo LIKE bar;
Así que las claves y los índices se copian sobre como, bien.
305
Author: RCNeil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-29 03:17:47
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-29 03:17:47
SHOW CREATE TABLE bar;
Obtendrá una instrucción create para esa tabla, editará el nombre de la tabla o cualquier otra cosa que desee, y luego la ejecutará.
Esto le permitirá copiar los índices y también modificar manualmente la creación de la tabla.
También puede ejecutar la consulta dentro de un programa.
19
Author: Timo Huovinen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-21 11:01:38
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-21 11:01:38