好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

PostgreSQL 自增语法的用法说明

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

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

?

1

2

3

4

5

6

7

create table company(

  id serial primary key ,

  name text not null ,

  age int not null ,

  address char (50),

  salary real

);

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

?

1

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

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

使用SERIAL关键字:

?

1

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

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

以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。如有错误或未考虑完全的地方,望不吝赐教。

原文链接:https://blog.csdn.net/huangbaokang/article/details/88868069

查看更多关于PostgreSQL 自增语法的用法说明的详细内容...

  阅读:39次