思想是先删除自增列,然后再重新添加一个自增列,序号就是从1开始连续的了。 alter table 表 drop column 自增编号列 alter table 表 add 自增编号列 int identity或者 把不包含ID列的数据插人的新表 select IDENTITY(INT,1,1) as id,[列名1],[列名2],[列名n] into [新表] from [旧表]
update table1 a,(select 自增列, (select count(*) from table1 where 自增列<=b.自增列) as new自增列 from table1 b) c set a.自增列=c.new自增列 where a.自增列=c.自增列
ALTER TABLE `table` DROP COLUMN `id`, ADD COLUMN `id` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT FIRST , DROP PRIMARY KEY, ADD PRIMARY KEY (`id`), AUTO_INCREMENT=1;
alter table 表 drop column 自增编号列
alter table 表 add 自增编号列 int identity或者 把不包含ID列的数据插人的新表
select IDENTITY(INT,1,1) as id,[列名1],[列名2],[列名n] into [新表] from [旧表]
set a.自增列=c.new自增列
where a.自增列=c.自增列
结帖率:0%当您的问题得到解答后请及时结贴.
http://bbs.csdn.net/topics/300235728
http://bbs.csdn.net/topics/330267949
http://bbs.csdn.net/topics/3401569384、如何给帖子结帖,结帖如何给分?
http://bbs.csdn.net/help#post_dispose
DROP COLUMN `id`,
ADD COLUMN `id` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT FIRST ,
DROP PRIMARY KEY,
ADD PRIMARY KEY (`id`),
AUTO_INCREMENT=1;