CREATE TRIGGER tg_groups_delete ON tc_groups FOR DELETE AS BEGIN UPDATE tc_groups SET groupid = NULL WHERE groupid IN (SELECT deleted.id FROM deleted) END CREATE TRIGGER tg_users_delete ON tc_users FOR DELETE AS BEGIN DELETE FROM tc_user_user WHERE manageduserid IN (SELECT deleted.id FROM deleted) END