Oracle creates primary key self-add table (SQL statement implementation) and trigger application _oracle

Source: Internet
Author: User
1. Create a table
Copy Code code as follows:

Createtabletest_increase (
Useridnumber (Ten) notnullprimarykey,/* primary key, automatically increase * *
USERNAMEVARCHAR2 (20)
);

2. Create automatic growth sequence
Copy Code code as follows:

Createsequencetestincrease_sequence
incrementby1--add a few at a time
startwith1--counting starting from 1
nomaxvalue--do not set maximum value, set maximum: maxvalue9999
nocycle--has been accumulated, does not cycle
CACHE10;

3. Create triggers
Copy Code code as follows:

Createtriggertest_increasebefore
insertontest_increaseforeachrow/* for each row to detect whether the trigger/
Begin
selectTestIncrease_Sequence.nextvalinto:New.useridfromdual;
End
* Exit Sqlplus Line Edit * *

4. Submit
Copy Code code as follows:

Commit

5, testing
Insertinto
Copy Code code as follows:

Test_increase (Username) VALUES (' Test ');
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.