我是菜鸟,简单的触发器问题,急。

lx47 2003-09-29 10:53:02
CREATE TRIGGER del ON dbo.CreditInsurance
FOR DELETE
AS
delete from Gatheringprawn
where Gatheringprawn.insurecode = (select insurecode from deleted)

CreditInsurance 是财务总表,Gatheringprawn是流水帐表
我想在总表每一次被删除一条记录后,都把他对应的流水帐全部删除,
这个触发器老是报错,说(select insurecode from deleted)的返回值不止一条。
请高人指点一二。
...全文
40 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lx47 2003-09-29
  • 打赏
  • 举报
回复
问题是为什么他报错说子查询的返回记录大于一条呢? 我只删除一条记录啊,实在没道理,
这个DELETED到底是代表什么呢?
chenxf220403 2003-09-29
  • 打赏
  • 举报
回复
同意楼上的说法,你现在看来只能用“in”作为检索条件进行删除,不过如果你担心会发生错误的话,可以为Deleted表定义一个游标,然后根据游标的记录指针再逐一删除流水表中数据。
lx47 2003-09-29
  • 打赏
  • 举报
回复
还是不行啊,55555555555~~~~~~~
还是报错:
subquery returned more than 1 value
this is not permitted when the subquery fallows = <,<=,>=,>,!=
or the subquery is uesed as an expression
到底是什么原因呢?应该没有其他因素的影响啊,我只是在数据库中写了这个TRRIG,然后在另一个表里(CreditInsurance )删除一条记录啊
txlicenhe 2003-09-29
  • 打赏
  • 举报
回复
CREATE TRIGGER del ON dbo.CreditInsurance
FOR DELETE
AS

delete Gatheringprawn
where Gatheringprawn.insurecode in (select insurecode from deleted)

lx47 2003-09-29
  • 打赏
  • 举报
回复
还是不行啊,还是报错:
subquery returned more than 1 value
this is not permitted when the subquery fallows = <,<=,>=.>
or the subquery is uesed as an expression
yujohny 2003-09-29
  • 打赏
  • 举报
回复
CREATE TRIGGER del ON dbo.CreditInsurance
FOR DELETE
AS
SET NOCOUNT ON

delete from Gatheringprawn
where Gatheringprawn.insurecode = (select insurecode from deleted)
westbulls 2003-09-29
  • 打赏
  • 举报
回复
其实我今天早上也犯了和你一样的错误,但是最终被我发现并改正了. ^-^
westbulls 2003-09-29
  • 打赏
  • 举报
回复
我觉得可能是你的gatheringprawn表中还有删除触发器,这个错误是它报的,你最好看一看.
yujohny 2003-09-29
  • 打赏
  • 举报
回复
CREATE TRIGGER del ON dbo.CreditInsurance
FOR DELETE
AS
set nocount on
delete from Gatheringprawn
where insurecode in (select insurecode from deleted)
lx47 2003-09-29
  • 打赏
  • 举报
回复
还是不行,真的烦操,不知是怎么了,哎,我都试过好多种写法了,全都报同一个错,返回记录不止一条
sdhdy 2003-09-29
  • 打赏
  • 举报
回复
按理说不会的。
try:
CREATE TRIGGER del ON dbo.CreditInsurance
FOR DELETE
AS
set nocount on
delete Gatheringprawn from deleted where Gatheringprawn.insurecode = deleted.insurecode


jilate 2003-09-29
  • 打赏
  • 举报
回复
他保留了你删除的那条记录
把 = 该为 in

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧