2012中创建了Identity的表,定义如下:  

 

createtable testidentity(idintidentity(1,1),name varchar(10))

 

插入10条测试数据:

 

insertinto testidentity values ('a')

go 10

 

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

 

selectIDENT_CURRENT('testidentity')

 

插入十条记录结果:

 

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

 

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

 

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

 

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

 

注意: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