Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mydogdating
Starting Member
5 Posts |
Posted - 2006-12-26 : 14:06:55
|
HiI have an issue with using trigger. What I want to do is when I insert a new product in a table, it will fire trigger in order to find matching products depending on material and color, and enter matching productIDs. It works great when I am looking for only one matching product. However, I want to have multiple matching products for a new product, insert value of each matching ID into Matching1, Matching2, Matching3... etc. How can I do it? Please help me out here. |
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-12-26 : 15:00:00
|
Before going any further with the trigger, you need to design your tables correctly or use queries to get matching products. Don't have Matching1, Matching2 etc. in the Product table. If you have Matching10 and there are 11 matching products then what happens?I'd say you should do what you want with queries, there should not need to be any reason to maintain the matches as extra data. You just query the product table with criteia that get all matching products. To do this you'd use a self join, where you reference the same table more than once in the FROM clause of a single query.If you do decide to keep the matching products in the data don't use MatchingX columns in the Product table, create a separate matching products table, with a row for each match that references the primary key IDs of the two matching products. |
 |
|
|
|
|