SQL Bulk Delete and BULK insert

Source: Internet
Author: User
Tags bulk insert

Bulk Delete:

DELETE from MyTable WHERE ID in (;

BULK INSERT:

INSERT into MyTable (id,name) VALUES (1, ' 123 ');
INSERT into MyTable (id,name) VALUES (2, ' 456 ');
INSERT into MyTable (id,name) VALUES (3, ' 789 ');

The second method uses union ALL to insert the operation:
INSERT into MyTable (id,name)
SELECT 4, ' 000 '
UNION All
SELECT 5, ' 001 '
UNION All
SELECT 6, ' 002 ';
It's said to be faster than the first!

The third method of
INSERT into MyTable (id,name) VALUES (7, ' 003 '), (8, ' 004 '), (9, ' 005 ');

Example:

Table: Leafjob (
Leafnum INT not NULL PRIMARY KEY,
Machine VARCHAR (15));

Delete: Delete from leafjob where Leafnum in (1,2,4);

Insert:

INSERT into Leafjob (leafnum, machine) VALUES (1, ' r1leaf3 '), (2, ' r1leaf22 ');

Insert into Leafjob (leafnum, machine) Select 4, ' The ' union ALL select 1, ' R1LEAF3 ' union ALL Select 2, ' R1leaf22 ';

Insert into Leafjob (leafnum, machine) Select 1, ' R1LEAF3 ' union select 2, ' R1leaf22 ';

Note: Performance issues require specific testing. Example tested under MySQL, version:4.1.20

SQL Bulk Delete and BULK insert

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.