Skip to content

Instantly share code, notes, and snippets.

@karthiks
Created November 11, 2021 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthiks/007fbe9c21a73aa426cc37c35504589b to your computer and use it in GitHub Desktop.
Save karthiks/007fbe9c21a73aa426cc37c35504589b to your computer and use it in GitHub Desktop.
Bulk Copy in SQL Server
# This one is bash, bcoz bcp is a cmd line utility
# https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-ver15#examples
# WideWorldImporters can be downloaded from https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v1.0
bcp WideWorldImporters.Warehouse.StockItemTransactions out D:\BCP\StockItemTransactions_character.bcp -c -T
# Bulk Insert
BULK INSERT YourTargetTable FROM '\\shared\directory\sourcedata.txt';
BULK INSERT Sales.Invoices
FROM 'inv-2017-12-08.csv'
WITH (DATA_SOURCE = 'MyAzureBlobStorage');
# OpenRowset(BULK..)
INSERT INTO YourTargetTable with (TABLOCK) (id, description)
SELECT * FROM OPENROWSET(
BULK 'csv/datasource.csv',
DATA_SOURCE = 'MyAzureBlobStorage',
FORMAT ='CSV',
FORMATFILE='csv/achievements-c.xml',
FORMATFILE_DATA_SOURCE = 'MyAzureBlobStorage') AS DataFile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment