SQL inserts data into the table with the primary key self-increment

Source: Internet
Author: User

SQL inserts data into the table with the primary key self-increment

1. Building an Index

--Create sequence Create sequence Seq_new_old_mgeminvalue 1400maxvalue 999999999999999999999999999start with 1420increment by 1cache 20;

Note: Create sequence seq_new_old_mge, Min. 1400, Max 999999999999999999 (I don't know if it's a few 9, according to the actual random), starting from 1420, every +1, buffer 20.

2. Use Index to insert data

INSERT into New_old_mge (pk,new_id,new_name,old_id,old_name) Select Seq_new_old_mge.nextval,p.pm_num,p.pm_name, T.admin_id,t.admin_name from Basedata.ts_admin_department T left join Gdbasedata.new_old_mge n on n.old_id = T.admin _id or N.old_name = T.admin_name left joins Gdbasedata.port_mge p on p.pm_num = t.admin_id or p.pm_name = T.admin_nam e where n.new_id is null and p.pm_num are NOT null

Fix it. Where PK is the self-increasing primary key, using sequence seq_new_old_mge.nextval to increase.

SQL inserts data into the table with the primary key self-increment

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.