Primary Key Increase by Trigger
Oracle Create Table:
CREATE TABLE TAB(
ID NUMBER(10) NOT NULL PRIMARY KEY,
NAME VARCHAR(19) NOT NULL
);
Drop table when exists:
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE TAB';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;
Create sequence as id:
CREATE SEQUENCE ID_SEQ_TAB
START WITH 1
INCREMENT BY 1
MINVALUE 1
NOMAXVALUE
NOCACHE;
Drop sequence when exists:
BEGIN
EXECUTE IMMEDIATE 'DROP SEQUENCE ID_SEQ_TAB';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -2289 THEN
RAISE;
END IF;
END;
Create trigger:
CREATE OR REPLACE TRIGGER ID_TRI_TAB
BEFORE INSERT
ON TAB
FOR EACH ROW
WHEN(NEW.ID IS NULL)
BEGIN
SELECT ID_SEQ_TAB.NEXTVAL INTO :NEW.ID FROM DUAL;
END;
Insert into table:
Insert into table_name (column_name...) values(values...)
Select column names of a table:
select column_name from user_tab_columns
where table_name = 'YOUR TABLE NAME HERE';
ps:
- dual:
A mystery table in Oracle, You can select many things from this table:
Select a_squence_name.nextval from dual
- Select into from:
A copy operation on oracle.You can use it like this:
SELECT * INTO new_table_name [IN externaldatabase] FROM old_tablename
Primary Key Increase by Trigger的更多相关文章
- 分区实践 A PRIMARY KEY must include all columns in the table's partitioning function
MySQL :: MySQL 8.0 Reference Manual :: 23 Partitioning https://dev.mysql.com/doc/refman/8.0/en/parti ...
- ORA-02429: cannot drop index used for enforcement of unique /primary key
相信不少人遇到过ORA-02429: cannot drop index used for enforcement of unique /primary key 这个错误,对应的中文提示"O ...
- SQL PRIMARY KEY 约束\SQL FOREIGN KEY 约束\SQL CHECK 约束
SQL PRIMARY KEY 约束 PRIMARY KEY 约束唯一标识数据库表中的每条记录. 主键必须包含唯一的值. 主键列不能包含 NULL 值. 每个表都应该有一个主键,并且每个表只能有一个主 ...
- Hibernate Id Generator and Primary Key
Use automate id by hibernate: If you want the tables' id be created automation. How to do it? When u ...
- Database Primary key and Foreign key [From Internet]
Database Primary key and Foreign key --Create Referenced Table CREATE TABLE Department ( DeptID int ...
- SQLite主键自增需要设置为integer PRIMARY KEY
按照正常的SQL语句,创建一个数据表,并设置主键是这样的语句: ), EventType )) 但使用这种办法,在SQLite中创建的的数据表,如果使用Insert语句插入记录,如下语句: INSER ...
- ASP.NET MVC another entity of the same type already has the same primary key value
ASP.NET MVC项目 Repository层中,Update.Delete总是失败 another entity of the same type already has the same pr ...
- 1503 - A PRIMARY KEY must include all columns in the table's partitioning function
1503 - A PRIMARY KEY must include all columns in the table's partitioning function 错误的原因:表的主键字段必须包含分 ...
- (转)Sqlite中INTEGER PRIMARY KEY AUTOINCREMENT和rowid的使用
原文:http://www.cnblogs.com/peida/archive/2008/11/29/1343832.html Sqlite中INTEGER PRIMARY KEY AUTOINCRE ...
随机推荐
- log4j.properties 输出指定类日志
比如,我只要众多日志中,红色框的日志,则可以指定类:com.dangdang.ddframe.rdb.sharding.parser.SQLParserFactory 修改配置文件: 再次输出结果为:
- Delphi XE2 之 FireMonkey 入门(30) - 数据绑定: TBindingsList: TBindExpression 的 OnAssigningValue 事件
Delphi XE2 之 FireMonkey 入门(30) - 数据绑定: TBindingsList: TBindExpression 的 OnAssigningValue 事件 表达式中的函数有 ...
- Noi2018 归途
zz:https://blog.csdn.net/dreaming__ldx/article/details/81106748 以海拔为第一关键字对边进行从大到小的排序,然后修建kruskal重构树, ...
- IDEA-包层级结构显示(三)
IntelliJ IDEA包层级结构显示 如:A.B.C,在项目中希望以如下形式显示: A B C 效果: 再更换为A.B.C形式显示
- 20191105 《Spring5高级编程》笔记-第9章
第9章 事务管理 一些名词: 2PC(2 Phase Commit) XA协议 JTS(Java Transaction Service) JCA(Java EE Connector Architec ...
- Java数组的使用
一.数组的动态初始化 1.声明数据类型[] 数组名;或数据类型 数组名[];2.开辟空间数组名 = new 数据类型[长度];//长度必不可少3.手动赋值数组名[下标] = 值;4.使用(打印.运算. ...
- 一个 Java 字符串到底有多少个字符?
来源:http://dwz.win/jqd 依照Java的文档, Java中的字符内部是以UTF-16编码方式表示的,最小值是 \u0000 (0),最大值是\uffff(65535), 也就是一个字 ...
- [2019杭电多校第四场][hdu6621]K-th Closest Distance(主席树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6621 题意为求区间[l,r]内第k小|a[i]-p|的值. 可以二分答案,如果二分的值为x,则判断区间 ...
- 一键生成APK
傻瓜式的生成APK网址:https://www.appbsl.com/ 第一步 第二步 第三步 第四步
- 生产者消费者模型(JoinableQueue)