- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
不确定哪个选项是最新的最佳实践?我继续阅读本教程:
https://www.postgresqltutorial.com/postgresql-identity-column/
PostgreSQL version 10 introduced a new constraint GENERATED ASIDENTITY that allows you to automatically assign a unique number to acolumn.
The GENERATED AS IDENTITY constraint is the SQL standard-conformingvariant of the good old SERIAL column.
CREATE TABLE color (
color_id INT GENERATED ALWAYS AS IDENTITY,
color_name VARCHAR NOT NULL
);
当您按照以下方式引用此表获取外键时:
CREATE TABLE pallet (
id INT GENERATED ALWAYS AS IDENTITY,
color_1 REFERENCES color
color_2 REFERENCES color
);
它现在会知道身份是主键吗?:
最佳答案
Will it know that the identity is the primary key now?
serial
也不会这样做)。
CREATE TABLE color (
color_id INT primary key GENERATED ALWAYS AS IDENTITY,
color_name VARCHAR NOT NULL
);
Not sure which option is latest best practice?
identity
而不是
serial
.
For new applications, identity columns should be used instead.
Why not serial?
The serial types have some weird behaviors that make schema, dependency, and permission management unnecessarily cumbersome.
serial
是 PostgreSQL 方言。
关于postgresql - 最好使用 SERIAL PRIMARY KEY 或 GENERATED ALWAYS AS IDENTITY 作为 PostgreSQL 中的主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64016778/
我是一名优秀的程序员,十分优秀!