大家救我啊~!关于SYBASE自递增字段的问题

jianten 2003-01-13 11:57:02
我的表的ID 设成 numice 类型,怎么有时明明 ID 为 5,下一个字录不为6,而已了500001 !!!!! 那ID经常会象这样数量级地向上翻倍~!这是什么原因啊?~!急!
...全文
165 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jianten 2003-01-14
  • 打赏
  • 举报
回复
谢谢 wanghai(汪海) !!

一点小分,不成敬意!!
wanghai 2003-01-14
  • 打赏
  • 举报
回复
如果为12。5,还有救

Sybase12.5新特性:关于identity_gap

表中可设置的系列号(identity列)间距

  表中含有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.


exp_row_size reservepagegap fillfactor max_rows_per_page identity_gap
----------------- -------------------- ----------- ------------------------- ---------------
1      0      0   0        10
concurrency_opt_threshold
--------------------------------
0
(return status = 0)
jianten 2003-01-13
  • 打赏
  • 举报
回复
好多错字呢,应是这样的:
如上一个记录ID 为5,下一个突然变成了 500006,然后过了一段时间又翻成了 1000000 ,这是什么原因啊~!(ID为自递增字段)

2,598

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧