当前位置:网站首页>Oracle primary key auto increment
Oracle primary key auto increment
2022-07-02 15:22:00 【SherlockerSun】
Oracle The primary key increases automatically
1、 Build table
CREATE TABLE TEST_TABLE
(
ID INT NOT NULL,
NAME VARCHAR2(40) NULL,
AGE VARCHAR2(40) NULL
);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.

2、 Set primary key
ALTER TABLE TEST_TABLE ADD CONSTRAINT TEST_TABLE_PK PRIMARY KEY (ID);
- 1.

3、 New sequence
CREATE SEQUENCE TEST_TABLE_AUTOINC_SEQ
MINVALUE 1
NOMAXVALUE
INCREMENT BY 1
START WITH 1
NOCACHE;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.

4、 New trigger
CREATE OR REPLACE TRIGGER TEST_TABLE_AUTOINC_TG
BEFORE INSERT ON TEST_TABLE FOR EACH ROW
BEGIN
SELECT TEST_TABLE_AUTOINC_SEQ.NEXTVAL INTO:NEW.ID FROM DUAL;
END;
- 1.
- 2.
- 3.
- 4.
- 5.

5、 test
INSERT INTO TEST_TABLE (NAME,AGE)VALUES(' test 1','18');
INSERT INTO TEST_TABLE (NAME,AGE)VALUES(' test 2','19');
INSERT INTO TEST_TABLE (NAME,AGE)VALUES(' test 3','20');
- 1.
- 2.
- 3.

6、 result
SELECT * FROM TEST_TABLE;
- 1.

边栏推荐
- Leetcode - Search 2D matrix
- 2021-2022學年編譯原理考試重點[華僑大學]
- QML pop-up frame, customizable
- GeoServer offline map service construction and layer Publishing
- 08_ strand
- 12_ Redis_ Bitmap_ command
- C # delay, start the timer in the thread, and obtain the system time
- 19_Redis_宕机后手动配置主机
- 表格响应式布局小技巧
- Principles, language, compilation, interpretation
猜你喜欢

FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)

04_ Stack

15_ Redis_ Redis. Conf detailed explanation

Let your HMI have more advantages. Fet-g2ld-c core board is a good choice

Practical debugging skills

面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?

TiDB数据迁移工具概览

How to avoid 7 common problems in mobile and network availability testing

07_哈希

Why can't programmers who can only program become excellent developers?
随机推荐
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
19_Redis_宕机后手动配置主机
JVM architecture, classloader, parental delegation mechanism
让您的HMI更具优势,FET-G2LD-C核心板是个好选择
Key points of compilation principle examination in 2021-2022 academic year [overseas Chinese University]
如何对 TiDB 进行 TPC-C 测试
Implementation of n queen in C language
C thread transfer parameters
MFC CString to char*
.NET Core 日志系统
05_队列
14_Redis_乐观锁
C language exercises - (array)
C RichTextBox controls the maximum number of lines displayed
Case introduction and problem analysis of microservice
03_线性表_链表
TiDB跨数据中心部署拓扑
【C语言】详解指针的初阶和进阶以及注意点(1)
18_Redis_Redis主从复制&&集群搭建
XML配置文件