944,084 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 1754
  • MS SQL RSS
May 16th, 2006
0

chicken and egg problem

Expand Post »
Hi All,
I have a problem with a table level constraint i want to create.
i have 3 tables:
products
categories
product_categories - use to connect product to categories since a product can be added to more then one category.

my problem is i want to create a contraint in the product table that makes sure all products belongs to atlist 1 category - meaning it exists in the products_categories table - but when i create a new product and before i added it to some categories i broke the constarint.

Any solutions?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tomermiz is offline Offline
1 posts
since May 2006
May 17th, 2006
0

Re: chicken and egg problem

I don't know if it is possible to do a two way foreign key constraint. I would suggest handling the problem procedurally. In other words, create a stored procedure for inserting into the product table that requires you to pass a category to be inserted into the product_categories table. and then only insert using that stored proc
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
May 20th, 2006
0

Re: chicken and egg problem

or a trigger
pty
Reputation Points: 64
Solved Threads: 39
Posting Pro
pty is offline Offline
530 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: SQL problem - table names as variables
Next Thread in MS SQL Forum Timeline: HELP - Invalid object error related to sqlole null bug in MSSQL 2000





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC