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 ...
随机推荐
- java操作solr
<dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</a ...
- original和source的区别
最近跟网页翻译怼上了,在给翻译前的页面起名是纠结于使用original page还是source page,就查了一下original和source的区别. original: n. 原件:原作:原物 ...
- centos修改时区,同步时间
查看当前系统时区 ls -la /etc/localtime 查看支持的时区 timedatectl list-timezones # 查看所有时区 timedatectl list-timezone ...
- Jmeter之CSV Data Set Config
在很多情况下,需要针对测试数据做参数化操作,Jmeter提供了很好用的CSV Data Set Config插件. 一.界面显示 二.界面说明 1.名称:标识,建议设置为该组件是提供什么功能 2.注释 ...
- SoapUI乱码问题处理方法
前言 每个工具都会有一些意想不到的“坑”,SoapUI也不例外.无论是参数或者响应报文,大家可能都遇到过乱码问题,这里记录一下几种解决乱码的方法. 一.修改显示字体 在File>>> ...
- A heavy dew refreshed the earth at night
brightness.n.明亮 endless.adj.无止境的 degradation.n.堕落 superiority.n.优越性 valuable.adj.有价值的 flake.n.小薄片 cu ...
- Monte Carlo Policy Evaluation
Model-Based and Model-Free In the previous several posts, we mainly talked about Model-Based Reinfor ...
- 20190905 Lombok常用注解
Lombok常用注解 val 用于声明类型,将从初始化表达式推断出类型,仅适用于局部变量和foreach循环,而不适用于字段.声明的局部变量为final变量. Java自带类型推断随着JDK版本提升越 ...
- vue—两个数组,去重相同项
- Soap从入门到实战
Soap从入门到实战 参考文章:https://howtodoinjava.com/spring-boot/spring-soap-client-webservicetemplate/ 使用的技术:s ...