MariaDB学习 专题
您的位置:database > MariaDB学习专题 > MariaDB 克隆表
MariaDB 克隆表
作者:--    发布时间:2019-11-20

某些情况下需要生成现有表的精确副本。 create ... select语句不能产生此输出,因为它忽略了索引和默认值。

复制表的过程如下 - 

  • 使用show create table来生成详细描述源表的整个结构的create table语句。

  • 编辑语句以给表一个新名称,并执行它。

  • 如果还需要复制表数据,请使用insert into ... select语句。

mysql> insert into inventory_copy_tbl (
   product_id,product_name,product_manufacturer,ship_date)
   
   select product_id,product_name,product_manufacturer,ship_date,
   from inventory_tbl;

另一种创建副本的方法使用create table as语句。 该语句复制所有列,列定义,并用源表数据填充副本。

检查其语法如下 -

create table clone_tbl as
   select columns
   from original_tbl
   where conditions];

查看其使用示例如下 -

create table products_copy_tbl as
   select *
   from products_tbl;

网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册