SQL Server trigger to update counter in second table -


i need solve question , i'm having serious issues working solution.

i have 2 tables, employees , departments. each department has counter of number of employees registered in them.

so, when insert or delete employee, pertinent department name, need update counter of department in departments table.

try creating (delete) trigger on employee table in after deleting employee, trigger runs , update department table.

create trigger updept

on employee

after delete

as update department d set d.empcount = (select count(employee) deptid = d.deptid) go

you may have set update query per data in table.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -