在单个 SQL 查询中插入多行? [英] Inserting multiple rows in a single SQL query?

查看:46
本文介绍了在单个 SQL 查询中插入多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要一次插入多组数据,比如说 4 行.我的表有三列:PersonIdOffice.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆