简体   繁体   English

如何在不从数据库表复制数据的情况下创建表结构?

[英]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.

相关问题 如何在创建时不复制数据的情况下创建类似于另一个表的表? - How to create a table similar to another table without copying the data at creation? 将数据从一个数据库表复制到不同服务器上的另一表 - Copying data from one database table to another table on different servers 复制表而不复制数据 - Copy table without copying data 将数据从一个表复制到另一个表。 数据库不同,表结构不同 - Copying data from one table to another table. Databases are different and table structure is different 从数据网格复制数据到数据库表中的无效操作异常 - invalid operation exception in copying data from data grid to database table 将数据从网格视图复制到数据库表中的mysql异常 - mysql exception in copying data from grid view to database table 如何从Mysql中的另一个表的列值创建表结构并插入数据 - How to create a table structure from column values of another table in Mysql and insert data 将数据从表A复制到表B时出错 - Error in copying data from table A to table B Mysql:如何从另一个数据库表更新表结构? - Mysql : how to update table structure from another database table? 如何使用jquery和ajax从数据库中的数据创建HTML表 - How to create a table in HTML from data in a database using jquery and ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM