简体   繁体   English

MySQL一对多对多对多转换

[英]MySQL One to Many to Many To Many Conversion

I have a table having one to many relationship. 我的桌子有一对多的关系。

tblAuthor
id
name

tblPublisher
id
name

tblBooks
title
author_id
publisher_id

I am converting it to hold multiple Authors and Multiple Publisher. 我正在将其转换为容纳多个作者和多个发布者。 So my new table schema is now. 所以现在是我的新表架构。

tblAuthor
id
name

tblPublisher
id
name

tblBooks
id
title

tblBooksAuthor
book_id
author_id

tblBooksPublisher
book_id
publihser_id

How can i migrate my data to new tables. 如何将数据迁移到新表。 And what is the best solution. 最好的解决方案是什么? tblBooks contain around 1M rows. tblBooks包含大约1M行。 Is insert into only way ? 是插入方式吗?

INSERT INTO tblBooksPublisher (book_id, publihser_id)
SELECT id, publihser_id
FROM tblBooks;

Are you migrating data from SQL to SQL or a different source? 您是将数据从SQL迁移到SQL还是其他来源? If you are just creating separate tables into SQL then yes, the easiest way would be to insert data regardless the amount of data you have. 如果只是在SQL中创建单独的表,则可以,最简单的方法是无论数据量多大都可以插入数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM