How to create a 1: N and 1: 1 relationship within the same table?

1

I have a table for image registration that is used as foreign key for other tables. The problem is that in one of these tables (PROMOCOES) the ratio is 1: N (a promotion for N images), while in the other tables the ratio is 1: 1. My question is how to organize these tables because I can not use foreign key within the table of images. Would it be better for me to create a specific table of promotion images, or create an intermediary table between PROMOCOES and images and continue using a single table of images?

    
asked by anonymous 19.07.2014 / 17:04

1 answer

3

By the normalization rules you should have a foreign key in the images table. But if you can not have this key you can create a table that relates images and promotions by continuing to use the table of images.

+----------+-----------+
| promo_id | imagem_id |
+----------+-----------+

It's the simplest way to do this, of course if you can not even put foreign key in the table images. Oh and do not forget about as primary key the 2 columns of this table.

    
19.07.2014 / 17:28