Adding Many Rows in One Query Using INSERT


INSERT book (author, title, cond)   VALUES     ('Maurice Sendak',      'In the Night Kitchen','mint'),     ('Caroll Spinney','How to Be a Grouch','poor'),     ('Dr. Seuss', 'Green Eggs and Ham', 'good');



The INSERT command can insert many rows in a single query by using multiple lists of values. Each set of values should be enclosed in parenthesis and separated by a comma. Place a semicolon after the final value list.

In addition to reducing the amount of typing that needs to be done, inserting multiple rows of data with a single SQL query has the advantage of efficiency: MySQL has to do less work than if it had to process three separate queries.



MySQL Phrasebook. Essential Code and Commands
MySQL Phrasebook
ISBN: 0672328399
EAN: 2147483647
Year: 2003
Pages: 130

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net