CREATE TABLE `t2` (
`code` varchar(100) DEFAULT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8
-- 添加主键
ALTER TABLE `t2` ADD COLUMN `ID` int(10) NOT NULL AUTO_INCREMENT AFTER `code`,ADD PRIMARY KEY (`id`)
use[你的数据库]
go
create
trigger
name
on
[table]
after
delete
as
begin
--定义游标,使你逐个往下找个ID,并执行update修改
declare
@flag
int
select
@flag=ID
from
deleted
declare
[cursorname]
cursor
for
select
ID
from
[table]
where
ID>@flag
open
[cursorname]
fetch
next
from
[cursorname]
update
[table]
set
ID=ID+1
where
ID=fetch
next
from
[cursorname]
WHILE
@@FETCH_STATUS
=
0
begin
update
[table]
set
ID=ID+1
where
ID=fetch
next
from
[cursorname]
close
[cursorname]
DEALLOCATE
authors_cursor
end
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)