mysql
sql自增
id int(11) not null auto_increment,primary key (id)mybatis model配置,让数据库生成id
@GeneratedValue(generator = "JDBC")查看下一个自增值
方式1:无法做筛选
show table status where name='表名'方式2:
select auto_increment from information_schema.tables where table_schema='数据库名' and table_name='表名'
postgresql
- 方式1:建表时自动建序列
建表
"id" serial not null设为主键
alter table 表名 add primary key ("id");获取id当前自增值
select currval('表名_id_seq')获取id下一个自增值
select nextval('表名_id_seq')
- 方式2:先建序列在建表
建序列
create sequence 序列名 increment by 1 minvalue 1 no maxvalue start with 1;建表
"id" int4 default nextval('序列名'::regclass) not null设为主键
alter table 表名 add primary key ("id");
- mybatis model配置,让数据库生成id
@GeneratedValue(generator = "JDBC")
oracle
建序列
create sequence 序列名 increment by 1 minvalue 1 no maxvalue start with 1;insert时id项的值为:
序列名.nextval或select 序列名.nextval from dualdual是虚拟表mybatis model配置,获取id值再进行insert操作
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "select 序列名.nextval from dual")查看所有序列
select * from user_sequences;