34,591
社区成员
发帖
与我相关
我的任务
分享
CREATE TABLE [tmptb] (
[f1] [int] IDENTITY (1, 1) NOT NULL ,
[f2] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
)
--插入
insert tmptb (f2)
select 'aaaaaaaaa' union all
select 'bbbbbb' union all
select 'ccccccc' union all
select 'dddddddd'
--删除2行
delete tmptb
where f1 in (2,3)
--再插入
insert tmptb (f2)
select 'qqqqqq' union all
select 'wwwwwww' union all
select 'eeeeeeee' union all
select 'rrrrrrrr'
--看效果
select f1,f2
from tmptb
--去除自增列
alter table tmptb drop column f1
--增加新自增列
alter table tmptb add f1 int identity(1,1)
--看效果
select f1,f2
from tmptb
DBCC CHECKIDENT(TB,RESEED,0)
/*
DBCC CHECKIDENT
检查指定表的当前标识值,如有必要,还对标识值进行更正。
语法
DBCC CHECKIDENT
( 'table_name'
[ , { NORESEED
| { RESEED [ , new_reseed_value ] }
}
]
)
参数
'table_name'
是要对其当前标识值进行检查的表名。表名必须符合标识符规则。有关更多信息,请参见使用标识符。指定的表必须包含标识列。
NORESEED
指定不应更正当前标识值。
RESEED
指定应该更正当前标识值。
new_reseed_value
是在标识列中重新赋值时要使用的值。
*/
truncate table 表名
tuncate table tb
alter table 表 drop column id
alter table 表 add id int identity(1,1)
A. 如有必要,重置当前标识值
下例在必要的情况下重置 jobs 表的当前标识值。
USE pubs
GO
DBCC CHECKIDENT (jobs)
GO
truncate table tb
truncate table tb