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

边栏推荐
- 2021-2022學年編譯原理考試重點[華僑大學]
- 16_ Redis_ Redis persistence
- Common English abbreviations for data analysis (I)
- 牛客练习赛101
- TiDB数据迁移工具概览
- FPGA - clock-03-clock management module (CMT) of internal structure of 7 Series FPGA
- 解决el-radio-group 回显后不能编辑问题
- Mfc a dialog calls B dialog function and passes parameters
- 可视化搭建页面工具的前世今生
- 12_ Redis_ Bitmap_ command
猜你喜欢

kibana 基础操作

Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?

C language exercises - (array)

yolo格式数据集处理(xml转txt)

05_队列

Btrace- (bytecode) dynamic tracking tool

I made an istio workshop. This is the first introduction

JVM architecture, classloader, parental delegation mechanism

20_Redis_哨兵模式

CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
随机推荐
FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)
编译原理课程实践——实现一个初等函数运算语言的解释器或编译器
06_栈和队列转换
Leetcode - Search 2D matrix
Topology architecture of the minimum deployment of tidb cluster
Mavn builds nexus private server
06_ Stack and queue conversion
原则、语言、编译、解释
实用调试技巧
MFC CString to char*
List set & UML diagram
03_線性錶_鏈錶
Kibana basic operation
學習使用php實現公曆農曆轉換的方法代碼
【C语言】详解指针的初阶和进阶以及注意点(1)
[noi simulation] Elis (greedy, simulation)
AtCoder Beginner Contest 254
语义分割学习笔记(一)
Record an interview
15_Redis_Redis.conf详解