删除某个或几个记录后,标记列重新自动增长问题

zgp28117034 2008-12-21 08:35:04
存储过程如下:
create procedure manu_del @id int
as
delete from 刊物信息表 where ID=@id
select * into a from 刊物信息表
truncate table 刊物信息表
set identity_insert a on
insert into 刊物信息表 select * from a
drop table a
go
检查语法出现如下错误信息:
“当使用了列的列表,并且IDENTITY_INSERT为ON时,才能在‘刊物信息表’中为标识显示值。”

我设计的刊物信息表结构中的ID为标记列
...全文
51 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gztiger 2008-12-23
  • 打赏
  • 举报
回复
conn.execute("manu_del("&id&")")
-晴天 2008-12-22
  • 打赏
  • 举报
回复
create procedure manu_del @id int 
as
delete from 刊物信息表 where ID=@id
select id=identity(int,1,1),name,vol,exp,pages,price... into a from 刊物信息表
truncate table 刊物信息表
set identity_insert 刊物信息表 on
insert into 刊物信息表(id,name,vol,exp,pages,price....) select * from a
set identity insert 刊物信息表 off
drop table a
go

采用set identity insert on 对插入表暂停自增列属性而入记录时,必须指明字段列表.且注意是对原表设置的.
上面的 name,vol,exp,pages,price.... 是我随便写的,根据你的表结构写上.
如果不对临时表设置一个新的自动列,再复制回刊物信息表后,id值并不会发生变化.
zgp28117034 2008-12-22
  • 打赏
  • 举报
回复
上面的问题解决了。
不过,我觉得效率有点低,如果数据记录有成千上万的话就要大打折扣了!所以我换了过程如下:
CREATE PROCEDURE manu_del @del_id int
AS
delete from 刊物信息表 where id=@del_id
select @del_id=@del_id-1
update 刊物信息表
set @del_id=@del_id+1,
id=@del_id
where id>@del_id
GO

<%
action=Request.QueryString("action")
if action=1 then
id=request.QueryString("id")
conn.execute("manu_del('"&id&"')")
conn.Close
set conn=nothing
Response.redirect "publication.asp"
end if
%>

结果如下:
Microsoft OLE DB Provider for SQL Server 错误
“&id&”附近有语法错误。
  • 打赏
  • 举报
回复
汗!有这个必要吗?
不就是把数据重新插入?
那效率能高得起来吗?

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧