Oracle Create primary key self-increment table

Source: Internet
Author: User

Introduction

This article focuses on the use of sequences in Oracle if you create a self-growth table.

Create Tabletb_student (ID Number(Ten) not NULL, Createtime DATE not NULL,   constraintPk_tb_studentPrimary Key(ID)); Comment on Table"Tb_student" is' StudentTable'; Comment on column"Tb_student". " Id is'primary Key ID'; Comment on column"Tb_student". " Createtime " is'creation Time';--Create a sequenceCreatesequence Seq_tb_studentminvalue1Nomaxvaluestart with 1Increment by 1nocycle--keep accumulating, not loopingNoCache; --Create a trigger if the INSERT statement does not specify an ID to automatically insert the growth valueCREATE OR REPLACE TRIGGERTr_tb_student beforeINSERT  onTb_student forEach ROW when(new.id is NULL)beginSelectSeq_tb_student.nextval into: new.id fromdual;End;

NOTE: Triggers are non-mandatory, and you can specify the insertion value from a business requirement.

Summary

Note Oracle restricts the object name to a character length of 30 characters, so the table name must be controlled at a certain length otherwise the creation sequence may exceed the limit, and it is recommended that the table name be controlled below 27 characters.

Note:

pursuer.chen

Blog:http://www.cnblogs.com/chenmh

This site all the essays are original, welcome to reprint, but reprint must indicate the source of the article, and at the beginning of the article clearly give the link.

Welcome to the exchange of discussions

Oracle Create primary key self-increment table

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.