我想在mysql中用触发器修改主键ID ;的值

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]se...
我想在mysql中用触发器修改主键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
end2019-06-07
mengvlog 阅读 67 次 更新于 2025-10-31 08:37:40 我来答关注问题0
檬味博客在线解答立即免费咨询

mySQL相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部