BULK
BULK is a SQL command that facilitates the rapid transfer of large amounts of data from a file into a SQL Server database. The main purpose is to provide an efficient mechanism for loading data into tables or views in SQL Server. Its primary benefit is in its speed, which is considerably faster than single-row insert statements. It can be used in combination with other SQL commands to streamline data import and processing tasks.
Example
Output
Explanation
In this example, a table Prices
with columns ItemID
and Price
is firstly created. The BULK INSERT
statement is then utilized to import data, specified in a text file (prices.txt
), into the Prices
table. The FIELDTERMINATOR
and ROWTERMINATOR
options define the delimiters separating fields and rows in the source data. The output simply notifies that three rows have been inserted into the Prices
table using the BULK INSERT
operation.
Example
Output
Explanation
The example declares a collection, t_names
, to hold employee names. It selects the first_name from the employees table using the BULK COLLECT
clause which bulk fetches the data and stores it into v_names
. The loop then prints out each name in the output.