[你的数据库]
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
如果表之前有主键则先删除:alter
table
表名
drop
constraint
主键名
修改主键:
alter
table
表名
add
constraint
主键名
primary
key
(column1,column2,....,column)
alter
table
t1
drop
column
c1
alter
table
t1
add
column
c1int
identity
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)