MySQL DatabaseLesson 63Free preview
MySQL Insert Multiple
This lesson is part of PHP · All levels
Summary
Many lines can be inserted into a single command by writing multiple tuple values separated by kam after VALUES. This is a much safer way because only one query travels to a MySQL server than writing INSERT one by one. For very large amounts of data, it is best to break it down into batches so that the query packet remains reasonable.
Key points
- One INSERT can contain many tuple: VALUES ('a', 1), ('b', 2), ('c', 3).
- All tuple must have a consistent number of columns and data type.
- Mass inserts are faster because they reduce the number of round-trip to the server.
- For thousands of lines of data, break into batches of several hundred lines.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.