if exists (select 1
from sysobjects
where id=object_id('TNT_depot')
and type='TR')
drop trigger TNT_depot
gocreate trigger TNT_depot on d_quota
for update
as
begin
declare @mchid varchar(10)
declare @get_mchid varchar(10)
if update(chk_sure)
begin set @mchid=(select parentid from j_depot where depotid=(select get_depotid from inserted))
set @get_mchid=(select get_mchid from inserted)
if @get_mchid<>@mchid
RAISERROR ('出错了!, 16, 1)
ROLLBACK TRANSACTION
end
end上面是我写的一个触发器,在进行单行更新的时候是没问题,而批量更新的时候,就会出问题。
请高手指定一下,应该怎么修改?
不胜感激。
from sysobjects
where id=object_id('TNT_depot')
and type='TR')
drop trigger TNT_depot
gocreate trigger TNT_depot on d_quota
for update
as
begin
declare @mchid varchar(10)
declare @get_mchid varchar(10)
if update(chk_sure)
begin set @mchid=(select parentid from j_depot where depotid=(select get_depotid from inserted))
set @get_mchid=(select get_mchid from inserted)
if @get_mchid<>@mchid
RAISERROR ('出错了!, 16, 1)
ROLLBACK TRANSACTION
end
end上面是我写的一个触发器,在进行单行更新的时候是没问题,而批量更新的时候,就会出问题。
请高手指定一下,应该怎么修改?
不胜感激。
解决方案 »
- sql2000与sql2005安装问题
- *****************请问如何随机生成160位长度的数字*******************
- 求一sql语句关于分组后的第一条记录
- 临时表建立索引问题
- 传递给 LEFT 或 SUBSTRING 函数的长度参数无效。
- 间隔相同的行数插入一个相同的数据,如何实现,各位高手帮帮忙!!!
- MS SQL SERVER数据库服务器有没有类似ORACLE计划任务?
- 高手看下我的聚合代码该如何写?
- 如何使window 2000 professional安装sqlserver2000 服务器端工具?
- SQL SERVER 插入数据
- 如果实现以下数据的重新排列?
- 如何一个语句获得 0801这种时间格式?
if exists (select 1
from sysobjects
where id=object_id('TNT_depot')
and type='TR')
drop trigger TNT_depot
go create trigger TNT_depot on d_quota
for update
as
begin
declare @mchid varchar(10)
declare @get_mchid varchar(10)
if update(chk_sure)
begin select @mchid=parentid from j_depot where depotid in (select get_depotid from inserted))
select @get_mchid=get_mchid from inserted
if @get_mchid <>@mchid
RAISERROR ('出错了!, 16, 1)
ROLLBACK TRANSACTION
end
end
if exists (select 1
from sysobjects
where id=object_id('TNT_depot')
and type='TR')
drop trigger TNT_depot
go create trigger TNT_depot on d_quota
for update
as
begin
declare @mchid varchar(10)
declare @get_mchid varchar(10)
if update(chk_sure)
begin select @mchid=parentid from j_depot where depotid in (select get_depotid from inserted))
select @get_mchid=get_mchid from inserted
if @get_mchid <>@mchid
RAISERROR ('出错了!, 16, 1)
ROLLBACK TRANSACTION
end
end
--这两行,子查询返回多个值
set @mchid=(select parentid from j_depot where depotid=(select get_depotid from inserted))
set @get_mchid=(select get_mchid from inserted)
if exists (select 1
from sysobjects
where id=object_id('TNT_depot')
and type='TR')
drop trigger TNT_depot
go create trigger TNT_depot on d_quota
for update
as
begin
declare @mchid varchar(10)
declare @get_mchid varchar(10)
if update(chk_sure)
begin select @mchid=parentid from j_depot where depotid in (select get_depotid from inserted))
select @get_mchid=get_mchid from inserted
if @get_mchid <>@mchid
RAISERROR ('出错了!, 16, 1)
ROLLBACK TRANSACTION
end
end
for update
as
begin
declare @count int
if update(chk_sure)
begin
set @count=@@rowcount
select 1 from (select parentid from j_depot where depotid in(select get_depotid from inserted)) aa inner join inserted bb on aa.parentid=bb.get_mchid
if @@rowcount<>@count
begin
RAISERROR ('出错了!', 16, 1)
ROLLBACK TRANSACTION
end
end
end
for update
as
begin
if update(chk_sure)
if exists(select * from j_depot a join inserted b on a.depotid=b.get_depotid and a.parentid<>b.get_mchid)
begin
RAISERROR ('出错了!',16,1)
ROLLBACK TRANSACTION
end
else
end 这样比价好
for update
as
begin
if update(chk_sure)
if exists(select * from j_depot a join inserted b on a.depotid=b.get_depotid and a.parentid<>b.get_mchid)
begin
RAISERROR ('出错了!',16,1)
ROLLBACK TRANSACTION
end
else
end 这样比价好
但是看不到是哪里有问题。在关键字 'end' 附近有语法错误。
create trigger TNT_depot on d_quota
for update
as
begin
if update(chk_sure)
begin
if exists(select * from j_depot a join inserted b on a.depotid=b.get_depotid and a.parentid<>b.get_mchid)
begin
RAISERROR ('出错了!',16,1)
ROLLBACK TRANSACTION
end
end
end
但是看不到是哪里有问题。 在关键字 'end' 附近有语法错误。
==========================================
create trigger TNT_depot on d_quota
for update
as
begin
if update(chk_sure) begin /*****/
if exists(select * from j_depot a join inserted b on a.depotid=b.get_depotid and a.parentid<>b.get_mchid)
begin
RAISERROR ('出错了!',16,1)
ROLLBACK TRANSACTION
end
else
end
for update
as
if NOT update(chk_sure)
RETURN
IF EXISTS(
SELECT 1
FROM
j_depot A
JOIN
inserted I ON A.depotid=I.get_depotid
WHERE
I.get_mchid<>A.parentid)
BEGIN
RAISERROR (N'出错了!', 16, 1)
ROLLBACK TRANSACTION
END