当前位置:网站首页>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.

边栏推荐
- C语言实现N皇后问题
- 08_ strand
- C language exercises - (array)
- 数据分析常见的英文缩写(一)
- FPGA - clock-03-clock management module (CMT) of internal structure of 7 Series FPGA
- How to write sensor data into computer database
- 05_ queue
- TiDB 环境与系统配置检查
- Topology architecture of the minimum deployment of tidb cluster
- 做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统
猜你喜欢

08_ 串
![[C language] explain the initial and advanced levels of the pointer and points for attention (1)](/img/61/1619bd2e959bae1b769963f66bab4e.png)
[C language] explain the initial and advanced levels of the pointer and points for attention (1)

20_ Redis_ Sentinel mode

20_Redis_哨兵模式

03_线性表_链表

你不知道的Set集合

14_Redis_乐观锁
![[noi Simulation Competition] scraping (dynamic planning)](/img/ee/27a07f80207a2925f5065e633eb39f.png)
[noi Simulation Competition] scraping (dynamic planning)

【C语音】详解指针进阶和注意点(2)

How does the computer set up speakers to play microphone sound
随机推荐
XML Configuration File
Real estate market trend outlook in 2022
PHP method to get the index value of the array item with the largest key value in the array
[c voice] explain the advanced pointer and points for attention (2)
03_ Linear table_ Linked list
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
20_Redis_哨兵模式
List set & UML diagram
Guangzhou Emergency Management Bureau issued a high temperature and high humidity chemical safety reminder in July
Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
19_Redis_宕机后手动配置主机
如何用 Sysbench 测试 TiDB
【C语言】详解指针的初阶和进阶以及注意点(1)
Record an interview
MFC CString to char*
14_Redis_乐观锁
Tidb cross data center deployment topology
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
How to solve the problem of database content output