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
温馨提示:答案为网友推荐,仅供参考
相似回答