0

I am in the process of designing a table for a promotion. I can promote three types of entities: article, photo and forum thread.

Initially I thought about creating one table with three foreign keys where only one would be set.

promotion: 
- id
- id_article
- id_photo
- id_thread
- promotion_type
- ... other properties

 article:
 - id
 - .. other properties

 photo:
 - id
 - .. other properties

 thread:
 - id
 - .. other properties

Is t a good approach? After initial thoughts it does look like there could be something "prettier" done here. promotion_type indicates which foreign keys tables should be joined.

SirKometa
  • 1,857
  • 3
  • 16
  • 26

1 Answers1

0

Instead of having 3 columns (id_article, id_photo, id_thread), just add one column.. Call it PromotionID for example, then you can still use PromotionType column to determine which table to tie.

The Promotion table would be as follows:-promotion: - id - PromotionID(either id_article, id_photo or id_thread) - promotion_type - ... other properties

Erick Kamamba
  • 268
  • 1
  • 4
  • 2
    I wouldn't like to weaken data integrity. With FK, sql server will check whether this id actually exist in the other table. – SirKometa Mar 21 '16 at 21:17
  • I have a similar usecase and if I follow this approach then I'll have to make sure the id exist manually and I'll have to fetch the data from the related table manually, any simpler way of doing this? – nick May 10 '22 at 08:06