复制关联表mysql_mysql关联表的复制

1. 复制被参照的表:

CREATE TABLE clone_product_1 LIKE product_1;

INSERT INTO clone_product_1 SELECT * FROM product_1;

2. 复制参照表:

1. 获取数据表的完整结构。

2. 修改SQL语句的数据表名,并执行SQL语句。

CREATE TABLE `clone_product_attribute_1` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`product_id` int(11) NOT NULL,

`variation_id` varchar(60) NOT NULL DEFAULT '',

`price` double NOT NULL,

`quantity` int(11) NOT NULL DEFAULT '0',

`reviews` int(11) NOT NULL DEFAULT '0',

`image` longtext NOT NULL,

`attributes` varchar(200) NOT NULL DEFAULT '{}',

`dictory` varchar(100) NOT NULL DEFAULT '',

`create_date` datetime NOT NULL,

`write_date` datetime NOT NULL,

PRIMARY KEY (`id`),

KEY `clone_product_attribute_1` (`product_id`),

CONSTRAINT `product_id_attribute_1` FOREIGN KEY (`product_id`) REFERENCES `clone_product_1` (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into clone_product_attribute_1 select * from product_attribute_1;

CREATE TABLE clone_product_26 LIKEproduct_26;INSERT INTO clone_product_26 SELECT * FROMproduct_26;CREATE TABLE`clone_product_attribute_26` (

`id`int(11) NOT NULLAUTO_INCREMENT,

`product_id`int(11) NOT NULL,

`variation_id`varchar(60) NOT NULL DEFAULT '',

`price`double NOT NULL,

`quantity`int(11) NOT NULL DEFAULT '0',

`reviews`int(11) NOT NULL DEFAULT '0',

`image` longtext NOT NULL,

`attributes`varchar(200) NOT NULL DEFAULT '{}',

`dictory`varchar(100) NOT NULL DEFAULT '',

`create_date`datetime NOT NULL,

`write_date`datetime NOT NULL,PRIMARY KEY(`id`),KEY`clone_product_attribute_26` (`product_id`),CONSTRAINT `clone_product_id_attribute_26` FOREIGN KEY (`product_id`) REFERENCES`clone_product_26` (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;insert into clone_product_attribute_26 select * fromproduct_attribute_26;CREATE TABLE`clone_product_detail_26` (

`id`int(11) NOT NULLAUTO_INCREMENT,

`product_id`int(11) NOT NULL,

`image` longtext NOT NULL,

`description` longtextNOT NULL,

`detail` longtextNOT NULL,

`shipping_to` longtextNOT NULL,

`feature` longtextNOT NULL,PRIMARY KEY(`id`),KEY`clone_product_detail_26` (`product_id`),CONSTRAINT `clone_product_id_detail_26` FOREIGN KEY (`product_id`) REFERENCES`clone_product_26` (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=3044 DEFAULT CHARSET=utf8;insert into clone_product_detail_26 select * fromproduct_detail_26;TRUNCATE TABLEproduct_detail_26;TRUNCATE TABLEproduct_attribute_26;DELETE FROMproduct_26;ALTER TABLE product_26 AUTO_INCREMENT = 1;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值