You are here: --/ mysql --/ Mysql – Thêm nhiều bản ghi

Mysql – Thêm nhiều bản ghi


Inserting Multiple Rows

INSERT inserts a single row into a table. But what if you needed to insert multiple rows? You could simply use multiple INSERTstatements, and could even submit them all at once, each terminated by a semicolon, like this:

• Input

INSERT INTO customers(cust_name,
   cust_address,
   cust_city,
   cust_state,
   cust_zip,
   cust_country)
VALUES('Pep E. LaPew',
   '100 Main Street',
   'Los Angeles',
   'CA',
   '90046',
   'USA');
INSERT INTO customers(cust_name,
   cust_address,
   cust_city,
   cust_state,
   cust_zip,
   cust_country)
VALUES('M. Martian',
   '42 Galaxy Way',
   'New York',
   'NY',
   '11213',
   'USA');
Or, as long as the column names (and order) are identical in eachINSERT, you could combine the statements as follows:
• Input
INSERT INTO customers(cust_name,
   cust_address,
   cust_city,
   cust_state,
   cust_zip,
   cust_country)
VALUES(
        'Pep E. LaPew',
        '100 Main Street',
        'Los Angeles',
        'CA',
        '90046',
        'USA'
     ),
      (
        'M. Martian',
        '42 Galaxy Way',
        'New York',
        'NY',
        '11213',
        'USA'
   );
Tip
Improving INSERT Performance This technique can improve the performance of your database possessing, as MySQL will process multiple insertions in a single INSERT faster than it will multipleINSERT statements.
copy from http://www.brainbell.com

Bài viết liên quan

Tags: , ,

Leave a Reply

 
Copyright © 20010 ..::VN Support::...All Right Reserved.
Design by Junkie and developed by Manlivo.
Contact:
  • sugiatinhyeu_thantinhyeu3
  • manlivo
  • manlivo@gmail.com
Powered by WordPress.
  • frontpage hit counter
  • Page Ranking Tool