首页 > 数据库技术 > 详细

mysql关联表的复制

时间:2016-07-19 16:55:05      阅读:250      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!