sybase字段属性,identity,设置跳跃值,手工插入自增初始值


使用sybase时将id字段设置为identity属性,即为自增。

但是sybase中自增时有时会跳跃,即,上一条还是5,下一条可能一下跳到50000+了。

with identity_gap = 1 on 'default'可以设置跳跃值为1。

set identity_insert test_table on 手工插入identity的值 1000

再插入一条id就是1001

create table test_table (
id                              numeric(18,0)                    identity ,
str1                            varchar(20)                      not null  
)
lock allpages
with identity_gap = 1 on 'default'
go

set identity_insert test_table on
go
insert into test_table(id,str1) values(1000,'bbb')

go
set identity_insert test_table off
go


set identity_update test_table on
go
update test_table set id=id+1000 where id<1000
go
set identity_update test_table off
go

insert into test_table(str1) values('ccc')

------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------

让表中则增字段从1000开始自增,跳跃度为1
create table test_table (
id                              numeric(18,0)                    identity ,
str1                            varchar(20)                      not null ,
PRIMARY KEY CLUSTERED ( id ) on 'default'
)
lock allpages
with identity_gap = 1 on 'default'
go
setuser
go

set identity_insert test_table on
go
insert into test_table(id,str1) values(1000,'111')
go
set identity_insert test_table off
go
delete from test_table
go

创建表的时候,设置 identity_gap = 1跳跃度为1

建表后打开identity手动开关,插入一条数据(id=1000),关

你可能感兴趣的:(sybase字段属性,identity,设置跳跃值,手工插入自增初始值)