Oracle uses Sequence and trigger to automatically increase the ID

Source: Internet
Author: User

Oracle uses Sequence and triggers to automatically increase IDs. Many companies use Oracle databases and require automatic increase of IDs. However, there is no ready-made method to use auto_increatment like SQL Server. Under www.2cto.com, I wrote a Sequence and a trigger to achieve automatic growth. (If you have a better method, please leave a message. Thank you.) 1. create a SequenceSql Code Create Sequence reader_sequence MINVALUE 1 MAXVALUE 999999999999999999999999999 start with 1 increment by 1 CACHE 20; 2. create a table SQL code -- permission create table privilege (id number (255) not null, -- sequential number name varchar2 (255 char) not null unique, -- permission name description varchar2 (char) null, -- permission description code varchar2 (64 char) not null unique, -- code feature varchar2 (64 char) not null, -- feature name module varchar2 (64 char) not null -- Module name primary key (id); www.2cto.com 3. add a trigger to the table to automatically obtain the ID SQL code create or replace trigger privilege_trigger before insert on privilege referencing old as old new as new for each row begin select reader_sequence.nextval into: new. id from dual; end;

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.