Oracle Build table sql+ Self-increment primary key

Source: Internet
Author: User

 --CREATE TABLE Bonus_benchmark_ VALUE---------------------------------------------------------------declare num number;    Begin select COUNT (1) into NUM from user_tables WHERE table_name = UPPER (' Bonus_benchmark_value ');     If Num>0 then execute immediate ' drop table Bonus_benchmark_value '; End If; end;/--------------------------------Table structure for bonus_benchmark_value------------------------------ CREATE TABLE bonus_benchmark_value ("benchmk_id" number not NULL, "Benchmk_year" NVARCHAR2 (a) NOT NULL, "Benchmk_code" NV ARCHAR2 () is not null, "Benchmk_value" NVARCHAR2 (a) NULL, "Measurement" NVARCHAR2 (a) null, "Reference_start" NVARCHAR2 ( NULL, "Reference_end" NVARCHAR2 (() null, "Benchmk_type" NVARCHAR2 () null) Loggingnocompressnocache;  
-- 创建序列,产生自增数值-- seq_BONUS_BENCHMARK_VALUE 序列名称create sequence seq_BONUS_BENCHMARK_VALUE start with 1 increment by 1;   --  创建触发器,在插入数据前,把自增数值赋值给主键--  seq_BONUS_BENCHMARK_VALUE 序列名称 --  BENCHMK_ID 主键idcreate or replace trigger TRIGGER_BONUS_BENCHMARK_VALUE       before insert on BONUS_BENCHMARK_VALUE       for each row       begin       select seq_BONUS_BENCHMARK_VALUE.nextval into :new.BENCHMK_ID from dual;      end ;   

Oracle Build table sql+ Self-increment primary key

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.