MySQL複製表結構和資料

2022-04-09 02:52:09 字數 546 閱讀 9122

mysql複製表有兩種方式,create table ascreate table like,這兩者還是有差別,需要根據不同的使用場景去選擇

1、create table as,可以複製表結構,但不能複製索引;可以在複製表結構的同時複製資料

複製表結構

1

create table new_table as select * from old_table where 1=0;

複製表結構和資料

1

create table new_table as select * from old_table;

2、create table like,可以複製表結構和索引

複製表結構

create table new_table like old_table;

mysql複製表結構和資料

sql語句方法 1.複製表結構及資料 create table test new select from test old create table shujuku.test new select from sys.test old 跨資料庫複製資料,shujuku和sys都是資料庫名 2.僅複製表...

mysql複製表資料 MySQL 複製表結構

介紹 有時候我們需要原封不動的複製一張表的表結構來生成一張新錶,mysql提供了兩種便捷的方法。例 create tabletb base idint not null primary key,namevarchar 10 keyix name name engine myisam charset ...

MySQL複製表結構和資料SQL語句

1.複製表結構及資料到新錶 create table 新錶 select from 舊表 2.只複製表結構到新錶 create table 新錶 select from 舊表 where 1 2 即 讓where條件不成立.方法二 由tianshibao提供 create table 新錶 like...