mysql關聯表的複製

來源:互聯網
上載者:User

標籤:

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關聯表的複製

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.