【发布时间】:2020-11-15 21:07:37
【问题描述】:
我将not null 放在主键列上,然后在我检查表的架构并且有not null 之后执行它
表:
-- auto-generated definition
create table warehouses
(
id_warehouse serial not null
constraint warehouse_pkey
primary key,
responsible_person varchar(30) not null
);
要删除的脚本不为空:
alter table warehouses
drop constraint warehouse_pkey;
alter table warehouses
alter id_warehouse drop not null;
alter table warehouses
add constraint warehouse_pkey
primary key (id_warehouse);
【问题讨论】:
-
PRIMARY KEY必须是NOT NULL,所以当您执行primary key (id_warehouse)时,您隐式添加了NOT NULL。如果您不希望这样,请将约束设置为UNIQUE而不是PRIMARY KEY。 -
你希望有尽可能多的
NOT NULL列,这样你的数据质量好,你的SQL语句变得简单快捷。
标签: postgresql datagrip