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
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
相关文章推荐
- SQL Server 2012 AlwaysOn Group 使用 Identity字段注意事项
- 使用SqlDependency监测SQL Server 2005/2008字段改动时的SQL语法及相关注意事项
- SQL Server中,给字段设置约束,设置默认值注意事项
- SQL Server 2012 安装杂谈(安装注意事项)
- SQL Server数据库中bit字段类型使用时的注意事项
- 在oracle中字段类型LONG的使用注意事项
- Windows Server 2008 R2 下安装 Sql Server 2012 注意事项
- .NET 2.0 SQL依赖注意事项(转载:原文《使用SQL Server 2005 Query Notification的几个注意事项》)
- SQL Server数据库中bit字段类型使用时的注意事项
- 基于VMware Workstation在Windows Server 2008 R2上搭建SQL Server 2012高可用性组(AlwaysOn Group)测试环境(二)
- 在Windows Server 2012 Failover Cluster环境下安装SQL Server的注意事项
- SQL Server中,timestamp类型使用注意事项
- 在oracle中字段类型LONG的使用注意事项
- 英文版SQL Server 2008使用时,字段中存在中文的要注意编码问题
- 在oracle中字段类型LONG的使用注意事项
- SQLite字段类型使用注意事项
- 基于Win2008 R2的WSFC实现 SQL Server 2012高可用性组(AlwaysOn Group)
- transient 字段使用注意事项
- 基于Windows Server 2008 R2的WSFC实现SQL Server 2012高可用性组(AlwaysOn Group)
- win10使用01:安装Sql Server 2008 r2的注意事项