Home > Database > Mysql Tutorial > Can SQL Insert Multiple Rows at Once?

Can SQL Insert Multiple Rows at Once?

DDD
Release: 2025-01-22 11:06:10
Original
739 people have browsed it

Can SQL Insert Multiple Rows at Once?

Can SQL insert multiple rows of data at one time?

When inserting multiple sets of data into a SQL table with multiple columns, writing separate INSERT statements for each row can be tedious. Fortunately, SQL Server 2008 provides a more efficient solution.

Multi-line INSERT statement

SQL Server 2008 supports inserting multiple rows into a table using a single INSERT statement. This can be accomplished by specifying multiple sets of values ​​within parentheses, separated by commas.

Grammar:

<code class="language-sql">INSERT INTO MyTable (Column1, Column2, Column3) VALUES
(Value1, Value2, Value3), (Value4, Value5, Value6)</code>
Copy after login

Example:

Suppose there is a table named "MyTable" with three columns: "Person", "Id" and "Office". To insert four rows of data, you can use the following statement:

<code class="language-sql">INSERT INTO MyTable
(Person, Id, Office)
VALUES
('John', 123, 'Lloyds Office'),
('Jane', 124, 'Lloyds Office'),
('Billy', 125, 'London Office'),
('Miranda', 126, 'Bristol Office');</code>
Copy after login

By taking advantage of this multi-row INSERT feature, you can simplify data insertion operations and improve the efficiency of your SQL queries.

The above is the detailed content of Can SQL Insert Multiple Rows at Once?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template