htdb=# create table httab(id serial primary key,name text,age int);
CREATE TABLE
htdb=# ALTER TABLE httab ADD CONSTRAINT httab_pkey PRIMARY KEY (id);
ALTER TABLE
查看表结构及约束
htdb=# \d httab
Table "public.httab"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+-----------------------------------
id | integer | | not null | nextval('httab_id_seq'::regclass)
name | text | | |
age | integer | | |
Indexes:
"httab_pkey" PRIMARY KEY, btree (id)
删除表主键
htdb=# alter table httab drop constraint httab_pkey;
ALTER TABLE
再次查询表结构
htdb=# \d httab
Table "public.httab"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+-----------------------------------
id | integer | | not null | nextval('httab_id_seq'::regclass)
name | text | | |
age | integer | | |
htdb=#
详情请参阅官方文档:点此跳转