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

边栏推荐
猜你喜欢

Kibana basic operation

搭载TI AM62x处理器,飞凌FET6254-C核心板首发上市!

可视化搭建页面工具的前世今生

18_Redis_Redis主从复制&&集群搭建

15_ Redis_ Redis. Conf detailed explanation

21_ Redis_ Analysis of redis cache penetration and avalanche

15_Redis_Redis.conf详解

Set set you don't know

飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测

17_ Redis_ Redis publish subscription
随机推荐
TiDB数据迁移工具概览
11_ Redis_ Hyperloglog_ command
传感器数据怎么写入电脑数据库
18_ Redis_ Redis master-slave replication & cluster building
06_栈和队列转换
Learn the method code example of converting timestamp to uppercase date using PHP
Mfc a dialog calls B dialog function and passes parameters
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
03_ Linear table_ Linked list
LeetCode_ String_ Simple_ 412.Fizz Buzz
QML pop-up frame, customizable
Tidb data migration scenario overview
Common English abbreviations for data analysis (I)
How to solve the problem of database content output
13_ Redis_ affair
XML配置文件
工程师评测 | RK3568开发板上手测试
Btrace- (bytecode) dynamic tracking tool
[noi Simulation Competition] scraping (dynamic planning)
学习使用php实现公历农历转换的方法代码