chicken and egg problem

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 1
Reputation: tomermiz is an unknown quantity at this point 
Solved Threads: 0
tomermiz tomermiz is offline Offline
Newbie Poster

chicken and egg problem

 
0
  #1
May 16th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: chicken and egg problem

 
0
  #2
May 17th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 523
Reputation: pty is on a distinguished road 
Solved Threads: 37
pty's Avatar
pty pty is offline Offline
Posting Pro

Re: chicken and egg problem

 
0
  #3
May 20th, 2006
or a trigger
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC