因为删除了很多条记录信息。id排序出现了断层
例如:1
2
3
...... 1001
1002
2001
怎样让他们重新初始化排序,1,2,3,......1001,1002,1003,......
例如:1
2
3
...... 1001
1002
2001
怎样让他们重新初始化排序,1,2,3,......1001,1002,1003,......
解决方案 »
- 按[出生日期]排序,每页8行,查询出第5页
- 求一本书(sql server 2005宝典,刘志勇编)源代码
- 怎么写个查询,把一个人一年的工资明细全部列出来?
- sql server 存储过程处理记录的问题
- SQLServer 2008 附加2005数据库文件报错,怎么办?请教下
- sql server 2005的一个用户删不掉
- 求序号列的生成办法SQL语句?
- 有知道如何估算表存储空间的兄弟吗?
- 请问如何将现有的sql数据库的文件数据导入到sql数据库
- 一般来说,创建的试图列的属性与数据来源保持一致,但我需要改变这种情况
- 统计全校各班级平均分在本班人数前60%的学生名单(发过类似贴,但没说清楚,请原谅),先感谢了!
- 数据库迁移问题
select top 5000 identity(int,1,1) as id into #t from sys.syscolumns a,sys.syscolumns b
select * from #t where id not in(select id from tb)
如果是SQL2005,可以排序如下。
SELECT ROW_NUMBER() OVER(ORDER BY GETDATE()) AS RID,*
FROM LI
这样可以取得新的ID
Rename Table关注
set @id=0update tb
set @id=@id+1,id=@id
而且这几种方法,不知怎么使用。
如果你们真的会,那就请详细说明。。谢谢
declare @table table (id int,col varchar(10))
insert into @table
select 1,'11' union all
select 2,'22' union all
select 3,'44' union all
select 1001,'66' union all
select 1002,'88' union all
select 2001,'99'select * from @table
/*
id col
----------- ----------
1 11
2 22
3 44
1001 66
1002 88
2001 99
*/
update @table
set id=cc.row
from
(
select row_number() over (order by a.id) as row ,a.id,a.col from @table a left join @table b on a.id=b.id
) cc left join @table d on cc.id=d.idselect * from @table
/*
id col
----------- ----------
1 11
2 22
3 44
4 66
5 88
6 99
*/
create table T (id int ,aa varchar(2),bb varchar(3))
insert T values(1,'11','111')
insert T values(3,'22','222')
insert T values(5,'33','333')
select id,aa,bb from T
id aa bb
----------- ---- ----
1 11 111
3 22 222
5 33 333(3 行受影响)alter table T DROP COLUMN id
--将id列删除外
alter table T add id int identity(1,1)
--添加新ID标识列
select id,aa,bb from Tid aa bb
----------- ---- ----
1 11 111
2 22 222
3 33 333(3 行受影响)
--sql2000 里可以这样
declare @table table (id int,col varchar(10))
insert into @table
select 1,'11' union all
select 2,'22' union all
select 3,'44' union all
select 1001,'66' union all
select 1002,'88' union all
select 2001,'99'select * from @tabledeclare @table2 table(id int identity(1,1) ,col varchar(10))insert into @table2 (col)
select col from @table order by idselect * from @table2
2.checkident重置起始值
DECLARE @TB TABLE([id] INT)
INSERT @TB
SELECT 1 UNION ALL
SELECT 2 UNION ALL
SELECT 3 UNION ALL
SELECT 1001 UNION ALL
SELECT 1002 UNION ALL
SELECT 2001declare @id int
set @id=0update @TB
set @id=@id+1,id=@idSELECT *
FROM @TB
/*
id
-----------
1
2
3
4
5
6
*/
1,先把自曾长列删除
2,在把数据插入临时表#T
select identity(int,1,1)as id,* into #T from 你的表
3,把原表数据
delete from 你的表
4,还原数据(你的表的表少一个id字段要加上)
insert into 你的表
select * from #T
5,需要把自曾长列属性加上!你在加上!
alter table tb drop column id
2,在把tb表数据插入临时表#T,并且从新加入ID列
select identity(int,1,1)as id,* into #T from TB
3,把原表数据删除
delete from tb
4,还原数据(你的表的表少一个id字段要加上)
select *
into tb
from #t