SQL根据现有表新建一张表,想新建一张表,新建的这张表结构要跟现有表结构相同,但不要现有表里面的数据!

看你用的什么数据库:

Sql server :

                 select * into table_new from table_old ;              复制结构和数据

                 select * into table_new from table_old where 1=2;              只复制结构

Oracle:

                 create table table_new as select * from table_old;                  复制结构和数据

                 create table table_new as select * from table_old where 1=0;       只复制结构

DB2:

                 --复制表结构

 create table table_name_new as (select * from table_name_old) definition only;

                 --插入数据

insert into table_name_new (select * from table_name_old);

MySql:

                 ----- 复制表结构及数据到新表

CREATE TABLE 新表 SELECT * FROM 旧表

                 ----- 只复制表结构到新表

CREATE TABLE 新表 SELECT * FROM 旧表 WHERE 1=2

猜你喜欢

转载自tom-tomcat.iteye.com/blog/2101636