简体   繁体   中英

Database Design - Design M-N relation

I'm going to design ERD . We have some places which can advertise in our site on different position of site . for example : Company A has 4 advertising on Homepage, Page B , Page C , Page D with 4 different price. How to design this structure?

I'm hesitating over using which of this ways:

1:

Place 
--------------
-placeID
-Address


Banner
--------------
-bannerID
-placeID
-price
-position ID
-priority


Position
-----------------
-positionID
-dimension

2:

Place 
--------------
-placeID
-Address


Banner
--------------
-bannerID
-content


Place-Banner
-----------------
-placebannerID
-placeID
-bannerID
-position
-price
-priority

Which of this ways can be correct?

Intuitively I'd go with the 2nd one, as it seems that writing queries there would be easier. But after some research I can say that the 1st variant is way better. Imagine that the place and banner stays the same, but only position changes. In 2nd variant it would cost more memory as you have to add entry to Place-Banner where there are 5 cols. In 1st variant it would take 4. Moreover position is reusable entity in 1st variant. And as far as I remember from university times 1st variant is of a higher DB normalisation form.

Second model is better and more normal. Because if you want to place one banner to multiple places, you will not have to repeat Banner content. This reduces update anomalies (less redundancy).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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