添加一个临时ID字段,用来生成新的编号 alter table 表 add tempid int identity(1,1)用自动的新编号来替换旧的编号 update 表 set 序号=tempid删除临时id字段 alter table 表 drop column tempid
不知你在什么工作环境下,如果是mssql server,那么在你建表的时候,好像可以添加一个自动序列字段,这种字段可以在你增加或删除记录的时候自动调整自己的值如果要自己搞,那么试试这个:(表名:example,有100条记录。字段名:id,现在删除了第59,60,61连续三条记录)update example set id=id-3 '删多少条就减多少。。 where id>59;注意,这语句只对删除连续几条记录有效,如果要删除不连续的几条记录,还得再想想。
首先,每删除一条记录时,要 dim delid as long
cn.execute "Update 表名 set id=id-1 where id> " & delid
删除多条记录时,分时段修改 ,假设被删除id 按增序排列 dim i as integer dim j as integer dim dblid() as long j=ubound(dblid)- lbound(dblid) cn.execute "Update 表名 set id=id - " & j & _ " where id> " dblid(i)
for i=ubound(dblid)-1 to lbound(dblid)+1 step -1 cn.execute "Update 表名 set id=id - " & i-lbound(dblid) & _ " where id between " & dblid(i-1) & " and " & dblid(i) next i
select出所有大于该ID的记录,循环每条记录的ID减少1
alter table 表 add tempid int identity(1,1)用自动的新编号来替换旧的编号
update 表 set 序号=tempid删除临时id字段
alter table 表 drop column tempid
set id=id-3 '删多少条就减多少。。
where id>59;注意,这语句只对删除连续几条记录有效,如果要删除不连续的几条记录,还得再想想。
首先,每删除一条记录时,要
dim delid as long
cn.execute "Update 表名 set id=id-1 where id> " & delid
删除多条记录时,分时段修改 ,假设被删除id 按增序排列
dim i as integer
dim j as integer
dim dblid() as long
j=ubound(dblid)- lbound(dblid)
cn.execute "Update 表名 set id=id - " & j & _
" where id> " dblid(i)
for i=ubound(dblid)-1 to lbound(dblid)+1 step -1
cn.execute "Update 表名 set id=id - " & i-lbound(dblid) & _
" where id between " & dblid(i-1) & " and " & dblid(i)
next i