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的更多相关文章

  1. 分区实践 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 ...

  2. 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 ...

  3. SQL PRIMARY KEY 约束\SQL FOREIGN KEY 约束\SQL CHECK 约束

    SQL PRIMARY KEY 约束 PRIMARY KEY 约束唯一标识数据库表中的每条记录. 主键必须包含唯一的值. 主键列不能包含 NULL 值. 每个表都应该有一个主键,并且每个表只能有一个主 ...

  4. 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 ...

  5. Database Primary key and Foreign key [From Internet]

    Database Primary key and Foreign key --Create Referenced Table CREATE TABLE Department ( DeptID int ...

  6. SQLite主键自增需要设置为integer PRIMARY KEY

    按照正常的SQL语句,创建一个数据表,并设置主键是这样的语句: ), EventType )) 但使用这种办法,在SQLite中创建的的数据表,如果使用Insert语句插入记录,如下语句: INSER ...

  7. 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 ...

  8. 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 错误的原因:表的主键字段必须包含分 ...

  9. (转)Sqlite中INTEGER PRIMARY KEY AUTOINCREMENT和rowid的使用

    原文:http://www.cnblogs.com/peida/archive/2008/11/29/1343832.html Sqlite中INTEGER PRIMARY KEY AUTOINCRE ...

随机推荐

  1. 软件-工具:Beyond Compare

    ylbtech-软件-工具:Beyond Compare 1.返回顶部 1. Beyond Compare是一套由Scooter Software推出的文件比较工具.主要用途是对比两个文件夹或者文件, ...

  2. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_05 IO字符流_8_使用try_catch_finally处理流中的异常

    变量没有初始化的赋值 变量可能赋值会失败.设置fw为null.close报错 把close也用try catch捕获异常 修改写入w盘.实际盘符没有这个 上面异常是这里打印的 继续优化代码

  3. http://bbs.csdn.net/topics/340046630 dbgrid怎么获取当前记录值

    这根grid无关,当你选中一条记录时,数据集就定位到这条数据上了,你只需要读取数据集中的数据就行了   对我有用[0] 丢个板砖[0] 引用 | 举报| 管理 hongss hongss 本版等级: ...

  4. winform控件CxFlatUI

    CxFlatUI https://github.com/HuJinguang/CxFlatUI    当前控件 AlertBox Button CheckBox DatePicker GroupBox ...

  5. python 正则表达式 re.match

    #coding:utf-8 import re #匹配内容:单词+空格+单词+任意字符 #\w 单词字符[A-Za-z0-9_] #(?P<name>...) 分组,除了原有的编号外在指定 ...

  6. oracle--单表查询

    ---单表的查询学习 --查询表的所有数据 select * from 表名;*代表所有 select * from emp; --查询表中指定字段的值 select 字段名1,字段名2,...fro ...

  7. Python3数据分析与挖掘建模实战 学习 教程

    Python3数据分析与挖掘建模实战 学习 教程 Python数据分析简介Python入门 运行:cmd下"python hello.py" 基本命令: 第三方库安装Windows ...

  8. HDFS数据流——读数据流程

    HDFS读数据流程 假设客户端请求下载文件/user/atguigu/ss.avi,HDFS读数据流程如下: 1)客户端向namenode请求下载文件,namenode通过查询元数据,找到文件所有文件 ...

  9. 小白学Python(15)——pyecharts 绘制树形图表 Tree

    Tree-基本示例 import json import os from pyecharts import options as opts from pyecharts.charts import P ...

  10. SpringMVC Controller单例和多例(转)

    首先上测试代码 import org.springframework.context.annotation.Scope; import org.springframework.stereotype.C ...