Get the App
SLTechnology News&Howtos  ›  Database  › 

SQL inserts data in bulk

Shulou Source: shulou.com Published: 2022-06-01 03:11:23 09月17日 Update

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.

Tags: Data statement obvious Field effect Database order Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB MySQL Docker Shulou Tech Info