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