Q132284591 发表于 2018-6-24 11:15:46

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

  在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会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
页: [1]
查看完整版本: SQL Server 2012 AlwaysOn Group 使用 Identity字段注意事项