Postgresql 有以下三种方法设置主键递增的方式,下面来看下相同点和不同点。
--方法一create table test_a
(
id serial,
name character varying(128),
constraint pk_test_a_id primary key( id)
);
NOTICE: CREATE TABLE will create implicit sequence "test_a_id_seq" for serial column "test_a.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_test_a_id" for table "test_a"
CREATE TABLE
--方法二create table test_b
(
id serial PRIMARY KEY,
name character varying(128)
);
NOTICE: CREATE TABLE will create implicit sequence "test_b_id_seq" for serial column "test_b.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test_b_pkey" for table "test_b"
CREATE TABLE
--方法三create table test_c
(
id integer PRIMARY KEY,
name char