请大家看看,如下形式的触发器如何写!!!急!

eagle_hb 2003-08-19 03:52:15
col1 col2
---------
a 1
b 2
c 3
d 4
要求随便删除一行以后,如删除第二行后,第二行的col2后的值全部减1,
变成如下所示
col1 col2
-----------
a 1
c 2
d 3

...全文
50 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2003-08-19
  • 打赏
  • 举报
回复
create trigger t_delete on 你的表
For Delete
As
update 你的表 set col2 = col2-1
where col1 > (select min(col1) from deleted)
chao778899 2003-08-19
  • 打赏
  • 举报
回复
create trigger on yourTable
For Delete
As
update yourTable set col2 = col2-1
where col1 > (select col1 from deleted)
dafu71 2003-08-19
  • 打赏
  • 举报
回复
ALTER TRIGGER [t_delete] ON [dbo].[yourtable]
FOR delete
AS
begin transaction
declare @pos int
select @pos=col2 from deleted
update yourtable set col2=col2-1 where col2>@pos
commit transaction
-------------------------接分
CrazyFor 2003-08-19
  • 打赏
  • 举报
回复
和ID标识的跳号是一样的

TRY:
表的删除触发器中加:

update 表 set col2=(select count(*) from 表 bb where bb.col2<表.col2)+1

lifeforu 2003-08-19
  • 打赏
  • 举报
回复
create trigger t on table for delete
as
update test set col2=col2-1 where col2>(select col2 from deleted)
txlicenhe 2003-08-19
  • 打赏
  • 举报
回复
create trigger on yourTable
For Delete
As
update yourTable set col2 = col2-1
where col1 > (select col1 from deleted)

or:
create trigger on yourTable
For Delete
As
declare @a varchar
select @a = col1 from deleted
update yourTable set col2 = col2-1
where col1 > @a

34,576

社区成员

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

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