第一个:
CREATE TRIGGER [更新数据] ON [dbo].[TABLE1]
FOR update
AS
if @@datefirst=5 return
SET DATEFIRST 5
update table1
set table1.顺序=table1.顺序+1
from table1,inserted,deleted
where table1.顺序>=inserted.顺序 and table1.编号<>inserted.编号
and deleted.顺序<>inserted.顺序
SET DATEFIRST 7
第二个:
CREATE TRIGGER [删除数据] ON [dbo].[TABLE1]
FOR delete
AS
SET DATEFIRST 5
update table1
set table1.顺序=table1.顺序-1
from table1,deleted
where table1.顺序>deleted.顺序
SET DATEFIRST 7
第三个:
CREATE TRIGGER [添加数据] ON [dbo].[TABLE1]
FOR INSERT
AS
SET DATEFIRST 5
update table1
set table1.顺序=table1.顺序+1
from table1,inserted
where table1.顺序>=inserted.顺序 and table1.编号<>inserted.编号
SET DATEFIRST 7