一个比较难的问题(高手请进)

我想用存储过程实现给表中标识序号的字段添加序列号,在每次对表修改后都进行同样的操作。例如:
序号 名称
1 黄瓜
2 西红柿
3 冬瓜
4 胡萝卜
当删除 2 西红柿时记录变为
1 黄瓜
2 冬瓜
3 胡萝卜
怎样实现???
[172 byte] By [xjspa-天涯] at [2008-2-13]
# 1
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
saucer-思归 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 2
sorry, ;-)

declare @id int
select @id = 序号 from yourtable where 名称 = '西红柿'
delete from yourtable where 序号 = @id
update yourtable set 序号 = 序号 -1 where 序号 > @id
saucer-思归 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 3
序号是每次都要变的,
并且不受用户控制,
序号完全的标识了
一共有多少记录让人一看就明白
xjspa-天涯 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 4
我能不能每次都把记录的序号重更新一边
xjspa-天涯 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 5
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 '西红柿'

saucer-思归 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 6
要实现你的功能,如在SERVER,每次都要更新很多记录,不如使用时在客户端添加.select convert(int,0) as recno,* from 表名 order by 序号
客户端生成
recno,序号,名称
再从第一条记录到最后一条个性客户端recordset的recno字段的值.
cxmcxm-小陈 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 7
谢谢各位
xjspa-天涯 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...