How Oracle builds a self-increment field on a table

Source: Internet
Author: User
This method for using sequence (sequence) For example has a table temp_test structure for: CREATE TABLE Temp_test
(
ID number,
NM varchar (10),
Primary key (ID)//ID is the primary key, and the following method sets it as the self-increment field
1, establish the self-increment sequence temp_test_idadd, name any, starting from 1, each add 1CREATE SEQUENCE temp_test_idadd INCREMENT by 1 start with 1; 2, in table temp_t Create a trigger on est as follows create OR REPLACE TRIGGER t_temp_test_idadd
Before INSERT on Temp_test
For each ROW
BEGIN
SELECT Temp_test_idadd. Nextval INTO:NEW.ID from DUAL;
END T_temp_test_idadd; Test results: Add data to the Temp_test table and execute the following statement two times insert into temp_test (NM)
VALUES (' SS '); The results are as follows:

How Oracle builds a self-increment field on a table

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.