日期:2014-05-19  浏览次数:20516 次

触发器的简单问题
想创建一个禁止删除指定行的触发器,请问我错在哪里?
CREATE   TRIGGER   DelAdmin   ON   Account
FOR   DELETE,UPDATE
AS
IF   (Delete   from   Account   Where   usertypeid= '99 ')
BEGIN
ROLLBACK   TRANSACTION
END


------解决方案--------------------
CREATE TRIGGER DelAdmin ON Account
FOR DELETE,UPDATE
AS
IF (Delete from Account Where usertypeid= '99 ')
BEGIN
ROLLBACK TRANSACTION
END

-----------------------------------
CREATE TRIGGER DelAdmin ON Account
FOR DELETE,UPDATE
AS
Delete from Account Where usertypeid= '99 '
if @@rowcount> 0


BEGIN
ROLLBACK TRANSACTION
END


------解决方案--------------------

CREATE TRIGGER DelAdmin ON Account
FOR DELETE
AS
IF exists(select 1 from Account Where usertypeid= '99 ')
BEGIN
ROLLBACK TRANSACTION
END