我被要求“创建触发器进行检查:当某人试图回收一台PC(删除)时,如果该PC位于计算机中,则需要显示一条警告消息”否,您不能删除任何PC”。会计部门。我已经尝试了以下方法,但是仍然可以从会计部门删除计算机。
create trigger NoDeleteAccountingPC
on computer
for delete
as begin
declare @LocationOfDelete char(20), @message char(60)
set @LocationOfDelete = (select location from pc where comp in (select comp from deleted))
if @LocationOfDelete = 'accounting'
begin
set @message = 'No, you cannot delete any PC'
raiserror (@message, 16, 1)
rollback tran
end
end