日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

sql插入多条记录_如何在SQL中插入多条记录

發布時間:2023/12/20 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sql插入多条记录_如何在SQL中插入多条记录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 — StackOverFlow

    SQL插入多行中-StackOverFlow

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

sql插入多條記錄

總結

以上是生活随笔為你收集整理的sql插入多条记录_如何在SQL中插入多条记录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。