sql插入多条记录

Hey, folks! In this article we will be focusing on ways to Insert Multiple rows in SQL.

嘿伙计! 在本文中,我们将重点介绍在SQL中插入多行的方法。

需要SQL插入INTO多行查询 (Need of SQL Insert INTO Multiple rows query)

SQL INSERT query inserts data into the columns of a particular table.

SQL INSERT查询将数据插入到特定表的列中。

The normal SQL INSERT query inputs the data values in a single row. In case when we want to insert data in multiple rows at once, this query fails.

普通SQL INSERT查询在一行中输入数据值。 如果我们要一次在多行中插入数据,此查询将失败。

Thus, in order to save the execution time, we need to use the SQL INSERT query in such a manner that it injects data into multiple rows at once.

因此,为了节省执行时间,我们需要使用SQL INSERT查询,以使其一次将数据注入到多行中。

Having understood the need of SQL Insert query for multiple rows, let us get started with the implementation of the same.

了解了多行SQL插入查询的需求之后,让我们开始执行相同的操作。



传统SQL INSERT查询可插入多个记录 (Traditional SQL INSERT query to insert multiple records)

Traditional SQL INSERT query injects input data into multiple rows. In this technique, we need to the insert query as many times we want to input data into the rows of the table.

传统SQL INSERT查询将输入数据注入多行。 在这种技术中,我们需要向表行中输入数据的次数要多次插入查询。

The basic drawback of this query is the overhead of execution of every insert query for multiple rows injection.

该查询的基本缺点是执行多行注入的每个插入查询的开销。

Example:

例:


create table Info(id integer, Cost integer, city varchar(200));
insert into Info(id, Cost,city) values(1, 100,"Pune");
insert into Info(id, Cost,city) values(2, 50, "Satara");
insert into Info(id, Cost,city) values(3, 65,"Pune");
insert into Info(id, Cost,city) values(4, 97,"Mumbai");
insert into Info(id, Cost,city) values(5, 12,"USA");
select * from Info;

Output:

输出:


1   100 Pune
2   50  Satara
3   65  Pune
4   97  Mumbai
5   12  USA


INSERT-SELECT-UNION查询以插入多个记录 (INSERT-SELECT-UNION query to insert multiple records)

In the above section, we got to know that INSERT INTO query injects multiple records. But, if we observer the output of it, we get to know that the clause ‘INSERT INTO’ is repeated many times.

在上一节中,我们了解了INSERT INTO查询将注入多条记录。 但是,如果我们观察它的输出,就会知道“ INSERT INTO”子句被重复了很多次。

Thus, we can use INSERT-SELECT-UNION query to insert data into multiple rows of the table.

因此,我们可以使用INSERT-SELECT-UNION查询将数据插入表的多行中。

The SQL UNION query helps to select all the data that has been enclosed by the SELECT query through the INSERT statement.

SQL UNION查询有助于通过INSERT语句选择SELECT查询所包含的所有数据。


create table Info(id integer, Cost integer);
INSERT INTO Info (id, Cost)
SELECT 1, '123'
UNION ALL
SELECT 2, '234'
UNION ALL
SELECT 3, '456';  select * from Info;

Output:

输出:


1   123
2   234
3   456


行构造以插入多个记录 (Row construction to insert multiple records)

The SQL INSERT query is used in a manner wherein we make use of a single INSERT query to insert multiple records within a single point of execution.

使用SQL INSERT查询的方式是,我们利用单个INSERT查询在单个执行点内插入多个记录。

Syntax:

句法:


INSERT INTO Table (columns)
VALUES (val1, val2, valN);

Example:

例:


create table Info(id integer, Cost integer,city nvarchar(200));
INSERT INTO Info (id,Cost,city)
VALUES (1,200, 'Pune'), (2, 150,'USA'), (3,345, 'France');  select * from Info;

Output:

输出:


1   200 Pune
2   150 USA
3   345 France


结论 (Conclusion)

By this we have come to the end of this topic. Herein we have covered three different techniques to INSERT data values across multiple records of a table.

至此,我们到了本主题的结尾。 本文中,我们介绍了三种不同的技术,可跨表的多个记录插入数据值。

Please feel free to comment in case you come across any doubt.

如果您有任何疑问,请随时发表评论。

For more such posts related to SQL, please visit SQL JournalDev.

有关与SQL有关的更多此类帖子,请访问SQL JournalDev 。



参考资料 (References)

  • SQL Insert into multiple rows — StackOverFlowSQL插入多行中-StackOverFlow

翻译自: https://www.journaldev.com/40783/sql-insert-multiple-rows

sql插入多条记录

sql插入多条记录_如何在SQL中插入多条记录相关推荐

  1. ai中如何插入签名_如何在PDF中插入一个或多个空白页?

    在编辑或修改PDF文档时,一般都需要新增空白页后再添加文本或图片等内容,那么如何在PDF中插入一个或多个空白页呢? 首先打开极速PDF编辑器,或打开需要编辑的PDF文档后,点击右上角"文档& ...

  2. 2016没有自带公式编辑器_如何在Visio中插入数学公式

    要使用Visio 2013之前必须先安装Office 2013,据了解和测试,只安装Visio没有安装Office是打开不了Visio的,因为Visio是Office的一个组件,那么如何在Visio中 ...

  3. ai中如何插入签名_如何在Word中插入特殊符号

    在写文档的过程中,时常需要用到一些特殊的符号,比如货币符号.形状符号等,那你知道这些符号如何添加吗? 1.货币符号怎么添加? 常常会输入一些货币符号,比如说¥.$.£等,那你一般是如何输入的?在哪里可 ...

  4. mysql怎么插入时间_如何在MySQL中插入日期?

    在MySQL中插入日期的方法:首先打开脚本文件:然后通过[INSERT INTO tablename (col_name, col_date) VALUE ('DATE: Auto CURDATE() ...

  5. ppt给图片增加高斯模糊_如何在PPT中插入大量图片而又保持其美感?

    这是我走了大量弯路之后的体会:与其一开始就去考虑用什么设计效果,不如先理清楚图片之间的关系如何.我们大致可以把一页PPT中插入多张图片的情况分为两种. 第一种情况是多张图片并列.这种情况非常常见,例如 ...

  6. word中如何插入 符号_如何在Word中插入版权或商标符号

    word中如何插入 符号 You can easily insert hundreds of symbols into your Word document with a few nimble key ...

  7. mysql 取出20条数据_“取出数据表中第10条到第20条记录”的sql语句+select top 使用方法...

    1.首先.select top使用方法: select * from table --  取全部数据.返回无序集合 select top n * from table -- 依据表内数据存储顺序取前n ...

  8. mysql查询第10到第20条记录_“取出数据表中第10条到第20条记录”的sql语句+selecttop用法...

    1.首先,select top用法: 参考问题 select top n * from和select * from的区别 select * from table -- 取所有数据,返回无序集合 sel ...

  9. sql怎么实现线性排序_如何在SQL中实现排序间接

    sql怎么实现线性排序 我最近偶然发现了一个有趣的Stack Overflow问题 ,该问题本质上是用户希望确保以明确定义的顺序交付结果记录. 他们写 SELECT name FROM product ...

  10. matlab两个图共用一个x轴_如何在Matlab中插入两个X轴图

    你可以做如下的事情.与@ Benoit_11的解决方案相比,我使用正常的Matlab标签,并用手柄引用两个轴,所以分配是明确的. 以下代码创建一个空x轴b,单位m / s的高度可忽略不计.之后,实际绘 ...

最新文章

  1. 如何给iOS 分类添加 属性
  2. 记一次错误的伪静态配置文件
  3. sdut 3363 驴友计划
  4. C++返回引用,使用引用接收和非引用接收的区别
  5. curl获取站点的各类响应时间(dns解析时间,响应时间,传输时间)
  6. Python操作Excel最好选择什么模块?
  7. 双十一 手淘技术用了这几招
  8. android项目中有哪几种依赖关系,Android Studio项目中三种依赖的添加方式
  9. 计算机系统-任务切换
  10. css中背景的应用及BFC与IFC应用
  11. BZOJ3997 TJOI2015组合数学(动态规划)
  12. java华氏度xhuan_华氏摄氏转换
  13. php怎么更换图片背景颜色,照片换底色红色变白色怎么变 怎么换照片底色
  14. idea关闭html校验,怎么样关闭IntelliJ IDEA的javascript提示
  15. 百果园app系统开发b2c模式详解
  16. 上海学车科目二,科目三容易扣分点分享,你了解多少
  17. 蓝牙 - 如何在Windows下抓取蓝牙数据
  18. MySQL-8.0 RESTART命令远程重启mysqld
  19. lisp画示坡线_示坡线画法图文教程
  20. Composite(组合模式)

热门文章

  1. cad2004教程_CAD卸载教程
  2. 2019最烂密码榜单出炉,教你设置神级密码!
  3. 千元喜提“随身影院”荣耀8x Max,告诉你移动刷剧是种什么体验?
  4. 【渝粤教育】电大中专计算机常用工具软件_1作业 题库
  5. CATIA_CAA_RADER26+VS2012安装教程
  6. ios蓝牙开发错误总结
  7. HCIA-RS(2019最新题库)
  8. table导出excel php_php导出excel表格的方法分享(代码)
  9. 关于大学生创新创业项目赛事汇总
  10. Tomcat8下载及安装配置教程(官网)