表中含有identity列,其值是由Adaptive Server 自动生成的唯一的ID序列号。由于缺省情况下服务器生成ID号的方式是根据全局变量@@identity决定当前输入表的identity列的ID号值,这样因为各种原因使得产生的序列号可能会有很大的间距,比如当Adaptive Server意外失败,或者执行 shutdown with nowait 停止Server,再重新启动Server以后,全局变量@@identity的值可能会变成一个大值。这种情况下可以通过 identity_gap 来控制序列号的最大间距。
使用create table 或者 select into 创建新表时可设置 identity_gap 参数的值:
create table tb_name(……) with identity_gap=value
select * into new_tbname with identity_gap=value from old_tbname
例如,创建一个带identity列的表tb1:
1> create table tb4 (y1 int,y2 numeric(5,0) identity) with identity_gap=5
2> go
1> insert tb4 values(11)
2> insert tb4 values(22)
3> insert tb4 values(33)
4> go
1> commit
2> go
1> shutdown with nowait
2> go
重新启动Adaptive Server,登录进来,执行如下操作:
1> insert tb4 values(44)
2> go
1> commit
2> go
1> select * from tb4
2> go
y1 y2
----------- --------
11 1
22 2
33 3
44 8
(4 rows affected)
要修改一个表中的identity_gap参数值,可以使用系统存储过程 sp_chgattribute ,具体语法为:
sp_chgattribute object_name,”identity_gap”,value
例如,修改表tb4中的identity_gap为10,可执行:
1> sp_chgattribute tb4, ”identity_gap”, 10
2> go
'identity_gap' attribute of object 'tb7' changed to 10.
(return status = 0)
要查看一个表的identity_gap参数的值,可通过系统存储过程sp_help tb_name,例如:
1> sp_help tb4
2> go
Name Owner Object_type
------------------------------ --------------------------- --------------------------------
tb4 dbo user table
(1 row affected)
Data_located_on_segment When_created
------------------------------ --------------------------
default Apr 10 2002 4:33PM
Column_name Type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name Identity
--------------- -------- ----------- ---- ----- ----- ------------------------------ ------------------------------ --------
h1 int 4 NULL NULL 0 NULL NULL NULL 0
h2 numeric 4 5 0 0 NULL NULL NULL 1
Object does not have any indexes.
No defined keys for this object.
Object is not partitioned.
Lock scheme Allpages
The attribute 'exp_row_size' is not applicable to tables with allpages lock scheme.
The attribute 'concurrency_opt_threshold' is not applicable to tables with
allpages lock scheme.