How to perform bulk insert operations in SQL Server?
In SQL Server, you can perform bulk insert operations using the following methods:
- Perform batch insertion operations using the INSERT INTO VALUES statement. For example:
INSERT INTO table_name (column1, column2)
VALUES (value1, value2),
(value3, value4),
(value5, value6);
- Perform bulk insert operations by combining the INSERT INTO SELECT statement with UNION ALL. For example:
INSERT INTO table_name (column1, column2)
SELECT value1, value2
UNION ALL
SELECT value3, value4
UNION ALL
SELECT value5, value6;
- Import data from an external file into a database table using the BULK INSERT statement. For example:
BULK INSERT table_name
FROM 'file_path'
WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n');
The above are some commonly used methods for performing batch insert operations, the specific method used depends on the data source and requirements.