Auto-increment id for oracle

Source: Internet
Author: User

-- Oracle Auto-increment id -- create a T_StudentInfo table create table T_StudentInfo ("id" integer not null primary key, xsName nvarchar2 (120) not null, xsAge integer not null, mobile varchar (12), Email varchar (50), Address nvarchar2 (300); -- create a sequence, sequence name: SEQ_StudentInfo_Identity -- create a sequence (sequence name rules generally start with SEQ, and then underline, followed by your table name, the T _ before the table name can be removed, end with _ Identity to indicate that this sequence is used in the sequence of Id auto-incrementing fields.) create sequence SEQ_StudentInfo_Identity increment by 1 -- add a few at a time, here I add 1 start with 1 each time -- count nomaxvalue from 1 -- do not set the maximum value nocycle -- always accumulate, do not cycle nocache; -- do not create a buffer -- you only have tables and sequences, you also need a trigger to execute it -- create a trigger whose name is Trg_Studentinfo_Identity -- I suggest that the trigger start with Trg _ followed by the table name, create trigger Trg_Studentinfo_Identity beforeinsert on T_StudentInfo for each row when (new. id is null) beginselect id_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.