开发者

How do I make this schema?

开发者 https://www.devze.com 2023-04-04 07:04 出处:网络
I have a table called tbl_AllowedIpRange with the columns: ipFrom | ipTo I have two tables that represent entities that can have allowed IP\'s assigned to them. tbl_Category and tbl_MediaItem.

I have a table called tbl_AllowedIpRange with the columns:

ipFrom | ipTo

I have two tables that represent entities that can have allowed IP's assigned to them. tbl_Category and tbl_MediaItem.

What im wondering is how I link 开发者_如何学运维the two tables to reuse the tbl_AllowedIpRange table and keep things in the 3nf?

I was thinking that I could put two columns in the tbl_AllowedIpRange table?

CategoryId | MediaItemId | ipFrom | ipTo

Then write a two methods to get the alloed ip for each table trying to get access to it.

NOTE: I cant use one single column for the foreign key in the tbl_AllowedIpRange because it will contain conflicting keys from the other tables as it will point to their primary keys....

Is there an easier way using a link table?


Your table tbl_AllowedIpRange should have an autoincrement PRIMARY KEY, which you can use to reference in other tables. So...

1. Add a referenceable primary key to the table tbl_AllowedIpRange

range_id | ipFrom | ipTo

2. Create a table to hold the relationship between tbl_Category and tbl_AllowedIpRange

Suggested table name: Category_AllowedIpRanges

category_id | range_id

3. Create a table to hold the relationship between tbl_MediaItem and tbl_AllowedIpRange

Suggested table name: MediaItem_AllowedIpRanges

mediaitem_id | range_id
0

精彩评论

暂无评论...
验证码 换一张
取 消