--因为数据库有些记录不需要了,要删掉,这样编号就断了,比如从1,2,3,4,6,删除编号为3和4的记录后,编号变为1,2,6,我想让现有数据从新排序,
--让编号变为1,2,3,再增加记录时,编号从4开始,该怎么写呢,请大家帮看一下。谢谢!
Create table test(id int identity(1,1),price int)
Insert into test
select 1 union
select 2 union
select 3 union
select 4 union
select 5 union
select 6
go
create trigger t
on test
for delete
as
Alter table test drop column id
ALTER TABLE test ADD id int identity(1,1)
go
delete test where id = 3
--因为数据库有些记录不需要了,要删掉,这样编号就断了,比如从1,2,3,4,6,删除编号为3和4的记录后,编号变为1,2,6,我想让现有数据从新排序,
--让编号变为1,2,3,再增加记录时,编号从4开始,该怎么写呢,请大家帮看一下。谢谢!
Create table test(id int identity(1,1),price int)
Insert into test
select 1 union
select 2 union
select 3 union
select 4 union
select 5 union
select 6
go
Select * from test
go
delete test where id in (3,4)
go
Select * from test
go
Alter table test drop column id
go
ALTER TABLE test ADD id int identity(1,1)
go
Select * from test
go
Drop table test
go