[英]How to create table structure without copying data from database table?
I was asked in a viva "how can you create a table structure without copying data from a database table?" 我被问到“如何在不从数据库表中复制数据的情况下创建表结构?” I was quite sure with my answer. 我的答案非常肯定。 My answer was:` 我的回答是:`
CREATE TABLE new_table AS (SELECT *FROM old_table );
Was I right or wrong? 我是对还是错?
CREATE TABLE new_table AS (SELECT * FROM old_table where 0=1);
No. Your answer is incorrect. 不,你的答案不对。 You can use this SQL query. 您可以使用此SQL查询。
CREATE TABLE *new_table* AS (SELECT *FROM *old_table* WHERE *statement=false*);
Like this an example is following: 像这样一个例子如下:
CREATE TABLE *new_table* AS (SELECT *FROM *old_table* WHERE *1=2*);
I think it will serve your purpose...:P 我认为这符合你的目的......:P
CREATE TABLE new_table AS SELECT * FROM old_table where 0=1;
在where子句中,我们可以使用任何不等式语句,例如1 = 2,2 = 3..etc。,这应该通知优化器这个'where'条件肯定会返回false,从而阻止从old_table复制任何数据。
if you are using workbench it has a option in left side of the screen "Data export" just click on it select the db you want to copy structure of and there will be a drop down option select "Dump structure only" and export to a folder. 如果您正在使用工作台,它在屏幕左侧有一个选项“数据导出”只需单击它选择要复制结构的数据库,将会有一个下拉选项选择“仅转储结构”并导出到夹。
import this file where ever you want using option data import restore and select path and type new schema name and import. 使用选项数据导入还原导入此文件,并选择路径并键入新的模式名称并导入。 you have new schema with the structure you want. 你有新的架构与你想要的结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.