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),关

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值