如何复制表结构、如何复制表数据

  1. 复制表的结构及其中的数据:
create table new_table_name as select * from old_table_name
  1. 只复制表的结构:
create table new_table_name as select * from old_table_name where 1=2;
  1. 只复制表数据:

若两个表的结构相同:

insert into new_table_name select * from old_table_name

若两个表的结构不同:

insert into new_table_name(col1,col2...) select col1,col2... from old_table_name

你可能感兴趣的:(数据库,sql)