ID auto-increment settings in ORACLE databases

Source: Internet
Author: User
I was supposed to migrate data from SQL Server to ORACLE. I did not expect that after the migration, the program would go wrong and cannot insert NULL. It is easy to think that the ID auto-increment mechanism of the two is different, problems may occur during direct migration. In SQLSERVER, it is very easy to add fields. You can identify the auto-increment on the lower point. But it is not that simple in ORACLE,

I was supposed to migrate data from SQL Server to ORACLE. I did not expect that after the migration, the program would go wrong and cannot insert NULL. It is easy to think that the ID auto-increment mechanism of the two is different, problems may occur during direct migration. In SQLSERVER, it is very easy to add fields. You can identify the auto-increment on the lower point. But it is not that simple in ORACLE,

I was supposed to migrate the data in SQL Server to ORACLE. I did not expect that after the migration, the program would fail to insert a NULL value, it is easy to think that because the ID auto-increment mechanism of the two is different, direct migration will cause problems. In SQLSERVER, it is very easy to add fields. You can identify the auto-increment on the lower point. However, it is not that simple in ORACLE, and you have not figured out why, ORACLE should divide the frequently used auto-increment fieldsSEQUENCE)AndTRIGGER)If you know the details and benefits, please do not give me some advice.

Because my table already exists, we only need to create the sequence and trigger in the two steps described above.

1. Create a sequence

Create sequence sq_logINCREMENT BY 1 -- add a few start with 700 each time -- the migrated data has recorded MINVALUE 1 -- Minimum value 1 NOMAXVALUE -- do not set the maximum value NOCYCLE -- always accumulate, non-circular NOCACHE-no buffer Creation

2. Create a trigger

    CREATE  TRIGGER tri_log    BEFORE    INSERT ON DBLOG    FOR EACH ROW    BEGIN        SELECT sq_log.nextval into :new.logid  from dual;    END tri_log;




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.