paddyfields
paddyfields

Reputation: 1539

suitable table design for relationships?

have two tables...

I want members to be able to save as many adverts as they wish.

The three methods I can think of are....

  1. A column in 'member' called 'savedAdvert' with a comma separated string of advert id's which increases as more are added.. like '123,143,15,235'

  2. A column in 'advert' called 'memberSaved' with a comma separated string of member id's which increases as more are added.. like '123,143,15,235'

  3. Make another table called 'SavedAds' with two columns of 'memberID', 'advertID' and each time a new advert is saved it adds a completely new row accordingly.

Which is the best method?

Upvotes: 0

Views: 63

Answers (1)

ApplePie
ApplePie

Reputation: 8942

Number 3 for sure.

Don't ever mention "comma separated string" in database design again. It is the worst possible design in a database in 99% of the cases (I can't come up with one case where it would be ok).

Method number 3 ensures that you have an easy way to find all the adverts for each member and vice versa. It's also very clean and easy to understand.

Upvotes: 3

Related Questions