PostgreSQL 自增语法的用法说明

来源:脚本之家 时间:2021-04-27

mysql使用auto_increment的语法实现表字段自增。

在PostgreSQL中,具有数据类型为smallserial,serial,bigserial的字段具有自增特性。

create table company(
 id serial primary key,
 name text not null,
 age int not null,
 address char(50),
 salary real
);

 

则在插入该表的时候,可以不插入id列,数据库系统会自动填充。

1insert into company(name,age,address,salary) values('huangbaokang',29,'ganzhou',100000);

补充:[Postgresql] 设置主键为自增长类型

使用SERIAL关键字:

1create table t(t_id SERIAL primary key,c1 text,c2 text,c3 text,c4 text);

导入数据时可不指定t_id字段,数据库会自动从1开始增长,默认为整型

文章来源:脚本之家

来源地址:https://www.jb51.net/article/205247.htm

相关文章

A5创业网 版权所有

返回顶部