一个比较难的问题(高手请进)
我想用存储过程实现给表中标识序号的字段添加序列号,在每次对表修改后都进行同样的操作。例如:
序号 名称
1 黄瓜
2 西红柿
3 冬瓜
4 胡萝卜
当删除 2 西红柿时记录变为
1 黄瓜
2 冬瓜
3 胡萝卜
怎样实现???
do not make 序号 as identity column, then when you delete 西红柿,
declare @id int
select @id = 序号 where 名称 = '西红柿'
delete from yourtable where 序号 = @id
update yourtable set 序号 = 序号 -1 where 序号 > @id
sorry, ;-)
declare @id int
select @id = 序号 from yourtable where 名称 = '西红柿'
delete from yourtable where 序号 = @id
update yourtable set 序号 = 序号 -1 where 序号 > @id
that is just a demo, try
Create proc DeleteFruit
@name nvarchar(100)
as
declare @id int
select @id = 序号 from yourtable where 名称 = @name
delete from yourtable where 序号 = @id
update yourtable set 序号 = 序号 -1 where 序号 > @id
then call
DeleteFruit '西红柿'
要实现你的功能,如在SERVER,每次都要更新很多记录,不如使用时在客户端添加.select convert(int,0) as recno,* from 表名 order by 序号
客户端生成
recno,序号,名称
再从第一条记录到最后一条个性客户端recordset的recno字段的值.