复制关联表mysql_mysql关联表的复制
发布日期:2021-06-24 07:11:24 浏览次数:5 分类:技术文章

本文共 2379 字,大约阅读时间需要 7 分钟。

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;

转载地址:https://blog.csdn.net/weixin_30909915/article/details/113296355 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:java mysql 表关系分析_数据库表的关系
下一篇:mysql unauthenticated user_出现 unauthenticated user Connect 怎么办

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月02日 13时49分18秒