db2回去自增主键当前值的例子

可以使用select max(id) from core;

也可以使用values(identity_val_local());   获取最后一次插入的自增主键值,否则,返回null。

create table  core(

id integer not null generated by default as identity (start with  1,increment by 1,cache 20, no minvalue,no maxvalue,no cycle,no order),
name varchar(20)

);


insert into core(name)
values('book');

select * from core;

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

ID,NAME
1,book

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

values(identity_val_local());   

1

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

重置:

alter table core alter column id restart with 1;

你可能感兴趣的:(DB2)