Like this, I guess:
create trigger TechStaff_update_Studio
on TechStaff after insert, delete
as
begin
update s set employees = employees
+ (select count(*) from inserted)
- (select count(*) from deleted)
from Studio s
end
Notice that you must actually count rows rather than assuming one row inserted/deleted per trigger execution (e.g. delete * from TechStaff
would fire the trigger once).
See MSDN on the inserted
and deleted
pseudo-tables.
And your where clause was always true (studioID = studioID
), and therefore not needed. I assume you did mean to update every row of the Studio table (is there only one row?).
Edit: Since you say there are multiple Studio
rows, you will need to be more clever. You have to get the count of deleted and inserted rows by StudioID. The following could probably be simplified, but I lack the time to make it shorter.
create trigger TechStaff_update_Studio
on TechStaff after insert, delete
as
begin
update s set employees = employees + c.Delta
from Studio s
join (
select StudioID, sum(i) as Delta
from (
select StudioID, 1 as i from inserted
union all
select StudioID, -1 as i from deleted
) counts
group by StudioID
) c on c.StudioID = s.StudioID
end