SQL Constraint/Check on Join tables

villagehub

New Member
I have three tables: \[code\]store\[/code\], \[code\]product\[/code\], \[code\]storeproduct\[/code\].It doesn't really matter what's in the \[code\]store\[/code\] and the \[code\]product\[/code\] table, just know there is a \[code\]storeID\[/code\] in the \[code\]store\[/code\] table, and a \[code\]productID\[/code\] in the \[code\]product\[/code\] table. However the \[code\]storeproduct\[/code\] table keeps track of the different \[code\]product\[/code\]s each \[code\]store\[/code\] has. So the \[code\]storeproduct\[/code\] table has two columns. The \[code\]storeID\[/code\] column, and the \[code\]productID\[/code\] column, both foreign keys from the \[code\]store\[/code\] and the \[code\]product\[/code\] table.Is there a way to put a constraint or check on any of the table to make sure that a store must have more than 0 products, and less than 50 products. Note: I do not want a \[code\]select\[/code\] statement to do this. I just want to know if there is a way to put a constraint or a check when creating the tables. The point of this is so a user cannot \[code\]insert\[/code\] into the \[code\]storeproduct\[/code\] table if there are already 50 products(rows) with the same \[code\]storeID\[/code\], or \[code\]delete\[/code\] from the \[code\]storeproduct\[/code\] table if deleting a row will cause the last row with that \[code\]storeID\[/code\] to be gone.The \[code\]storeproduct\[/code\] table might look like this\[code\]storeID productID1 11 21 32 42 52 62 73 43 23 63 13 8\[/code\]
 
Top