Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SQL inserts data in bulk

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Summary of sql statements for bulk insert data in MS SQL Server database:

The first kind:

Insert into tb_NameList (Name,InsertDate,UpdateDate)

Values ('aa',GETDATE (), GETDATE ())

Insert into tb_NameList (Name,InsertDate,UpdateDate)

Values ('bb',GETDATE (), GETDATE ())

Insert into tb_NameList (Name,InsertDate,UpdateDate)

Values ('cc',GETDATE (), GETDATE ())

In this way, all the statements are written and executed at once, which is actually the same as a single insert.

The second kind:

Insert into tb_NameList (Name,InsertDate,UpdateDate)

Values ('aa',GETDATE (), GETDATE ()), (' bb',GETDATE (), GETDATE ())

('cc',GETDATE (), GETDATE ())

This can write a lot less SQL statements, as long as the order of the Values is written clearly on OK.

The third kind:

Insert into tb_NameList (Name,InsertDate,UpdateDate)

Select 'dd',GETDATE (), GETDATE () union all

Select 'ee',GETDATE (), GETDATE () union all

Select 'ff',GETDATE (), GETDATE ()

With the help of union all, it is said to be faster than the second one, but the field is simple and the effect is not obvious with less data.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report