Default auto-increment of primary keys in Oracle

Source: Internet
Author: User

The default auto-Growth of primary keys in Oracle many times when database-related operations are performed, primary keys cannot be filled by users or when multiple users operate on one table at the same time, we need to strictly control the primary key. Here we will focus on how to achieve auto-growth of the primary key in Oracle. Www.2cto.com consists of three steps: 1) create a table; 2) create a sequence; 3) create a trigger (to enable the sequence generated value when inserting data in a table ), 1) create a database table: drop table TEST; create table TEST (bsm NUMBER (10) not null, xh NUMBER (10 ), posx NUMBER (15, 5), posy NUMBER (15, 5); alter table TEST add constraint PK_TEST primary key (BSM); 2) create a sequence drop sequence TEST_SEQ; create sequence TEST_SEQ minvalue 1 maxvalue 999999999999999999 start with 1 increment by 1 cache 20; Note: create a sequence with a minimum value of 1, count from 1 and increase each time as 1; 3) CREATE a trigger www.2cto.com drop TRIGGER test_trig; create or replace trigger "test_trig" before insert on test referencing old as old new as new for each row declare begin select TEST_SEQ.NEXTVAL INTO: NEW. bsm from dual; END test_trig

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.