当前位置:网站首页>How to set primary key self growth in PostgreSQL database
How to set primary key self growth in PostgreSQL database
2022-07-19 06:59:00 【He is a rookie programmer】
For the first time today postgresql database , Find it and mysql Is not the same , You cannot set the primary key with a view id Self growth , Therefore, you can add a sequence to the primary key , In this way, we can achieve self growth !
following , Is to add serialization and set serialization to id above sql sentence :
CREATE SEQUENCE "employee_management_emp_seq" // Set sequence name
INCREMENT 1 // Growth value
MINVALUE 1 // minimum value
MAXVALUE 999 // Maximum
START 1 // Initial value
CACHE 1; // cache The above values correspond to this figure , You can also add a sequence directly here
Click other , Then select the sequence

The last step is to set the newly added sequence to the primary key
alter table Table name alter column Primary key field name set default nextval('employee_management_emp_seq'( The sequence name just added ))It's done here ! At this time, just go back and look at your watch , You will find that the default constraints under the fields of the primary key are from NULL It's a sequence , Here's the picture :

边栏推荐
猜你喜欢

银河麒麟桌面操作系统V10SP1(X86)安装SQL Developer

【自动化测试】——robotframework实战(三)编写测试用例
Xiaodi network security notes - Information Collection - architecture, construction, WAF (8)

传奇手游怎么开服?需要投资多少?需要那些东西?

【自动化测试】——robotframework实战(一)搭建环境

SYN洪水攻击的原理,syn洪水攻击的解决办法

opensuse 安装网易云音乐(tumbleweed)(leap)

Slag learning road (2) pure white direction: win Server 2003 server building

小迪网络安全-笔记 加密编码算法(6)

notepad++下划线以及大小写字母置换
随机推荐
Temperature acquisition experiment and experimental experience based on I2C
Steam游戏服务器配置选择 IP
华为云 鲲鹏ARM云服务器 和 x86云服务器 性能评测对比
【自动化测试】——robotframework实战(一)搭建环境
FreeBSD 12 国内源提速 pkg 和 ports 做个笔记
银河麒麟服务器系统搭建本地和局域网yum源
Huawei routing port mapping
促进数字世界的信任
tail -f暂停方法
Homework
手动字符串比较(指针题)
邮资范围(数组 or +函数)
ARM开发环境入门
Openssl--- stack
University
SYN洪水攻击的原理,syn洪水攻击的解决办法
Performance evaluation and comparison of Huawei cloud Kunpeng arm ECs and x86 ECS
postgresql 数据库如何设置主键自增长
Gnome 安装扩展插件(40.1版本,opensuse tumbleweed)。
Double code time scale network diagram