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 |
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2008-04-30 : 08:55:03
|
| i have following two tables:table orders (id_order, order_date, customer_id)table orders_line (id_order, id_order_line, id_product, product_name)this two tables are filled automatically.and a third destination table as a backup table:table backup_order (id_order, order_date, id_order_line, id_product)this one is going to be filled by trigger.following will insert:----create trigger orders_product on orders_lineafter insertASinsert into backup_order (id_order, order_date, id_order_line, id_product)select o.id_order,o.order_date,ol.id_order_line ,ol.id_productfrom orders as ojoin orders_line as ol on o.id_order = ol.id_orderjoin inserted as i on i.id_order_line = ol.id_order_linewhere ol.id_product = 'ABC123Product']----now i need also a triggerthat will make insert and update on existing table:---CREATE trigger order_products on orders_linefor insert, updateas begin update backup_order set id_product = ol.id_product from orders_line as ol join inserted as i on i.id_order_line = ol.id_order_line where i.id_order_line = ol.id_order_line end----but it does not update new cell with new data.any suggestions? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-30 : 08:58:26
|
| Do you need seperate triggers? cant you include the code in single trigger itself? Also where is backup_order linked to other two tables data in update? |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2008-04-30 : 09:39:25
|
| visakh16: i'm making two triggers each for it's table (orders, orders_line).Idea is to have both triggered when new line/update occurs and all info should be gathers in backup_order. that's it. :) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-30 : 10:32:37
|
quote: Originally posted by visakh16 Do you need seperate triggers? cant you include the code in single trigger itself? Also where is backup_order linked to other two tables data in update?
As per code you posted you are creating both the triggers on same table orders_line |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|
|