您的位置:首页 > 数据库

SQL Server 2012 AlwaysOn Group 使用 Identity字段注意事项

2014-01-07 16:07 423 查看
在2012中创建了Identity的表,定义如下:  

 

create table testidentity(idint
identity(1,1),name
varchar(10))
 

插入10条测试数据:

 
insert into testidentity
values ('a')
go 10
 

做Failover之后发现Identity的值变为了1001.

 
select
IDENT_CURRENT('testidentity')
 

插入十条记录结果:

 

 


 

由于SQL Server会Cash identity
的值,所以可能会有Gap(比如rollback/restart),但是不应该这么大。

 

解决这个办法要使用Trace Flag 272:

 

 


 注意:Thiswill cause a log record to be generated for each generated identity value. Theperformance of identity generation
may be impacted by turning on this traceflag

 

也就意味着使用这个TraceFlag有额外的性能开销,如果Identity使用非常频繁的话注意。

 

另外可以考虑NO CACHE的方式,比如http://msdn.microsoft.com/en-us/library/ff878091.aspx

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: