Create a table in Oracle and add auto-incrementing Sequence

Source: Internet
Author: User

Oracle table Creation

Create table BI_MLK_SEARCHKEYWORD (

Id number (30) primary key,
KEYWORD varchar2 (30 ),
Times number (30) not null,
Inputdate date,
PINYIN VARCHAR2 (50 ),
FIRSTPINYIN VARCHAR2 (30 ),
ENGLISH VARCHAR2 (50)

);

Oracle creation Sequence

Drop sequence dectuser_tb_seq;
Create sequence dectuser_tb_seq minvalue 1 maxvalue 99999999
Increment by 1
Start with 1;/* The step size is 1 */

Add auto-incrementing sequence to a table
Create or replace trigger dectuser_tb_tri
Before insert on BI_MLK_SEARCHKEYWORD/* trigger condition: This trigger is triggered when the insert operation is performed on the dectuser table */
For each row/* checks whether each row is triggered */
Begin/* trigger start */
Select dectuser_tb_seq.nextval into: new. ID from dual;/* trigger topic content, that is, the action executed after the trigger, where the next value of the obtained sequence dectuser_tb_seq is inserted into the userid field in the dectuser table */
End;
Commit;

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.