码迷,mamicode.com
首页 > 数据库 > 详细

mysql关联表的复制

时间:2016-07-19 16:58:01      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

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;

mysql关联表的复制

标签:

原文地址:http://www.cnblogs.com/LicwStack/p/5685080.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!