postgres 不会掉落不为空
postgres doesn't drop not null
我将 not null
放在主键列上,它会在我检查 table 的模式并且有 not null
后执行
table:
-- 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);
根据此处的信息:
https://www.postgresql.org/docs/current/sql-createtable.html
PRIMARY KEY (column constraint)
The PRIMARY KEY constraint specifies that a column or columns of a table can contain only unique (non-duplicate), nonnull values. Only one primary key can be specified for a table, whether as a column constraint or a table constraint.
定义为 PRIMARY KEY
的列也将具有 NOT NULL
约束集。
我将 not null
放在主键列上,它会在我检查 table 的模式并且有 not null
table:
-- 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);
根据此处的信息:
https://www.postgresql.org/docs/current/sql-createtable.html
PRIMARY KEY (column constraint)
The PRIMARY KEY constraint specifies that a column or columns of a table can contain only unique (non-duplicate), nonnull values. Only one primary key can be specified for a table, whether as a column constraint or a table constraint.
定义为 PRIMARY KEY
的列也将具有 NOT NULL
约束集。