本文介绍了语法错误地触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想编写一个触发器,该触发器在执行一个元素的删除操作之前更新其他两个表.但是,我收到一条错误消息:无效的列名称.有人可以帮我吗?

谢谢

Hallo,

I want to write a trigger that updates two other tables before a delete operation of one element is executed. However I get an error message: Invalid column name. Can someone plese help me?

Thanks

CREATE TRIGGER [tbl_a].[tbl_a_trd] ON [tbl_a].[]
WITH EXECUTE AS CALLER
FOR DELETE
AS
DECLARE @number as int
DECLARE @maxint as int
DECLARE @mask as int
DECLARE @client as int
DECLARE @rc as int
SET @rc = @@ROWCOUNT;
IF @rc = 0 
RETURN;
IF @rc = 1
BEGIN

  set @number = (select number from deleted);
  set @maxint = 2147483647 ;
  set @mask = maxint - number;
  set @client = (select client from deleted);

  
  update tbl_b set flag = (flag & mask) where client = @client;
  
  update tbl_c set flag = (flag & mask) where client = @client;
  
END
GO

推荐答案

set @mask = maxint - number;


set @mask = @maxint - @number;






替换




also

Replace

update tbl_b set flag = (flag & mask) where client = @client;

  update tbl_c set flag = (flag & mask) where client = @client









with

update tbl_b set flag = (flag & @mask) where client = @client;

  update tbl_c set flag = (flag & @mask) where client = @client;





这应该工作





This should work


这篇关于语法错误地触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 20:56