Author |
Topic |
RBTrout
Starting Member
6 Posts |
Posted - 2011-03-06 : 14:21:47
|
I'm having trouble with triggers. I understand what they do, just having trouble creating one.I've got a DB with 3 tables - CustomersOrderHeaderOrderDetailI need to create a trigger that will not allow a customer to be deleted in that customer still has an order. THX for the help. |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
RBTrout
Starting Member
6 Posts |
Posted - 2011-03-06 : 14:57:31
|
After everything I've scoured in books and online, I agree completely. I'm taking a SQL class that wants me to do this and I'm completely stumped. I get stored procedures and functions, but triggers have me lost. I've got a mental block (on my shoulders, I think) on this. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
RBTrout
Starting Member
6 Posts |
Posted - 2011-03-06 : 18:16:35
|
use ProductOrdersGocreate trigger order_delete on orders after deleteASIf exists (select * From orders join customers On Orders.CustID = Customers.CustID Where Orders.CustID = Customers.CustID Raiserror('Customer still has order.',11,1) Rolback TranEndI usually get stuff like this, but I'm really drawing a blank. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
RBTrout
Starting Member
6 Posts |
Posted - 2011-03-06 : 18:53:55
|
Thanks! I've already read lines similar and didn't get it. I had to walk away and spend some time doing honey-dos and then come back with a fresh mind. NOW, that line makes sense and I get it.I really appreciate the help.....especially on a Sunday. Thanks again. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|