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 |
|
intern2424
Yak Posting Veteran
53 Posts |
Posted - 2009-12-06 : 16:00:58
|
| I was wondering if you can do an if statement like is Insert run the update else if Delete run update? Right now I two triggers. I have been trying to create just one.Alter TRIGGER insert_update_EmployeesON AssignmentFOR INSERT ASUPDATE PSET Num_Emp = num.Num_EmpFROMProject PINNER JOIN( Select Proj_num, [Num_Emp] = Count(Emp_num)From Assignment Group by Proj_Num) numONp.proj_num = num.proj_numPRINT 'Emp_Num has been Updated.';Thanks for any help you can give. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
intern2424
Yak Posting Veteran
53 Posts |
Posted - 2009-12-06 : 16:29:53
|
| I was just wondering if I can create one trigger to work with INSERT OR DELETE STATEMENT instead of two. Like insert(John, doe, 27, 1982, 15) I will insert john doe and update Num_emp but also if i run a delete on john doe it will update emp_num from the same trigger. Is this even possible or do I just have to use two triggers. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-12-06 : 17:32:41
|
create your trigger for insert,delete.check trigger tables inserted and deleted.if only deleted has values then there was no update. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
intern2424
Yak Posting Veteran
53 Posts |
Posted - 2009-12-06 : 19:00:24
|
| sorry for the double post. |
 |
|
|
|
|
|