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 ...
随机推荐
- AtomicStampedReference 源码分析
AtomicStampedReference AtomicStampedReference 能解决什么问题?什么时候使用 AtomicStampedReference? 1)AtomicStamped ...
- 001-spring boot概述与课程概要
一.Spring Boot介绍 Spring Boot的目的在于创建和启动新的基于spring框架的项目.Spring boot会选择最适合的Spring 子项目和第三方开源库进行整合.大部分Spri ...
- Delphi XE2 之 FireMonkey 入门(29) - 数据绑定: TBindingsList: 表达式的 Evaluate() 方法
Delphi XE2 之 FireMonkey 入门(29) - 数据绑定: TBindingsList: 表达式的 Evaluate() 方法 TBindingsList 中可能不止一个表达式, 通 ...
- 当在浏览器中输入一个url后回车,后台发生了什么?比如输入url后,你看到了百度的首页,那么这一切是如何发生的呢?
简单来书有以下步骤: 查找域名对应的IP地址.这一步会依次查找浏览器缓存,系统缓存,路由器缓存,ISPDNS缓存,13台根域名服务器. 向IP对应的服务器发送请求. 服务器响应请求,发回网页内容. 浏 ...
- django-xadmin常用内容记录
自定义菜单名称: 1 修改app下的 apps.py文件 添加 class OperationConfig(AppConfig): name = 'operation' verbose_name = ...
- AUTOGUI生成的一个简易文本编辑器
; Generated by AutoGUI #SingleInstance Force #NoEnv SetWorkingDir %A_ScriptDir% SetBatchLines - #Inc ...
- request.getParameter
request.getParameter(),该API针对的是 form表单entype的值为 application/x-www-form-urlencoded(默认值), 或者参数跟在地址栏上us ...
- git篇之二----团体项目中使用git
上篇说了git的简单入门,本篇来说一下在团体项目中我们该如何简单使用git 一般来说,当我们进入公司之后,就前端项目而言,若是有多个同事共同开发一个系统,我们可能会每个人去负责各自的模块. 若是人员较 ...
- 数组去重,排序,重复次数,两个数组合并,两个数组去重,map(),filter(),reduce()
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 回溯--- Permutations
46.Permutations (Medium)](https://leetcode.com/problems/permutations/description/) [1,2,3] have the ...