Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

sql - Relation between tables (BD)

I have the following information from two tables (Categories and Subcategories)

enter image description here

Note that in the Subcategories table, Subcategory 1 is repeated in two Categories; in Category A and Category B. My question is, when it comes to relating the two tables, and recording the data in the DB, what is the best way to do it?

At first, I considered relating the two tables directly, with a foreign key in the Subcategories table, and registering the subcategory that is repeated in the DB but in JSON format, like this:

enter image description here

But then I thought about having a detailed table in between, which would allow me to relate the two tables ... The point is that since there is only one subcategory that is repeated (subcategory 1), I don't know if it merits and is worth one detail table to relate the Categories and Subcategories tables; and I also don't know if storing IDs of another entity in JSON format is the best option ...

How can I do it better?

Thank you very much for any help and suggestions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...