Created
November 11, 2021 07:25
-
-
Save karthiks/007fbe9c21a73aa426cc37c35504589b to your computer and use it in GitHub Desktop.
Bulk Copy in SQL Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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