开发者

how do i create this association

开发者 https://www.devze.com 2023-03-08 13:24 出处:网络
i have the following 2 sql server tables Products locationCode (PK), prodId (PK), productName ---------------------------------

i have the following 2 sql server tables

Products
locationCode (PK), prodId (PK), productName
---------------------------------
AUG, 1, Widget
ATL, 1, Widget

Categories
prodId (PK) catId (PK), catName
----------------------------------
1, 1, WidgetsCategory
1, 1, WidgetsCategory

What would I need to do t开发者_如何学Goo create an association where a single product can have many categories given the required fields and (PK) Primary keys?


Create one more table that relates products to categories. This table should contain the key of products and a foreign key (category id).

In your original question you don't mention whether the location code matters or not. You also don't mention if this is a 1-N or M-N type relationship. Provide a bit more detail to get additional help.

When you normalize your tables you ensure every table has fields related with only itself (unless of course you are creating that relationship and you store the keys to make that relationship).

Your categories table should only include categories, and should not have anything to do with a product. Once you establish a Category entity, you then relate that category to another product, via another table.

0

精彩评论

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