在单个SQL查询中插入多行? [英] Inserting multiple rows in a single SQL query?
本文介绍了在单个SQL查询中插入多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一次要插入的多组数据,比如说4行.我的表有三列:Person
,Id
和Office
.
I have multiple set of data to insert at once, say 4 rows. My table has three columns: Person
, Id
and Office
.
INSERT INTO MyTable VALUES ("John", 123, "Lloyds Office");
INSERT INTO MyTable VALUES ("Jane", 124, "Lloyds Office");
INSERT INTO MyTable VALUES ("Billy", 125, "London Office");
INSERT INTO MyTable VALUES ("Miranda", 126, "Bristol Office");
我可以在一条SQL语句中插入所有4行吗?
Can I insert all 4 rows in a single SQL statement?
推荐答案
在SQL Server 2008中,您可以使用单个SQL INSERT语句插入多行.
In SQL Server 2008 you can insert multiple rows using a single SQL INSERT statement.
INSERT INTO MyTable ( Column1, Column2 ) VALUES
( Value1, Value2 ), ( Value1, Value2 )
作为参考,请查看MOC课程2778A-在SQL Server 2008中编写SQL查询.
For reference to this have a look at MOC Course 2778A - Writing SQL Queries in SQL Server 2008.
例如:
INSERT INTO MyTable
( Column1, Column2, Column3 )
VALUES
('John', 123, 'Lloyds Office'),
('Jane', 124, 'Lloyds Office'),
('Billy', 125, 'London Office'),
('Miranda', 126, 'Bristol Office');
这篇关于在单个SQL查询中插入多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文