/*date: June 2017author: rchupurpose: sql server bcp examples*//* create a table to play with */truncatetable[dbo].[tempchu];droptabletempchu;createtabletempchu(custNamevarchar(150),custAdrvarchar(50))/* Generate non-xml and xml format files from the tempchu table */--create format filebcp"[AdventureWorks2012].dbo.[tempchu]"formatnul-f"C:\myscratch\tempchu.fmt"-T-c-t,--create format xml filebcp"[AdventureWorks2012].dbo.[tempchu]"formatnul-c-x-f"C:\myscratch\tempchu.xml"–t,-T/* use the non-xml format file to load data into the table */bcp"[AdventureWorks2012].dbo.[tempchu]"IN"C:\myscratch\tempchu.csv"-c-f"C:\myscratch\tempchu.fmt"-T-Slocalhost/* Query the table. Verify that new data was loaded correctly */select*from[dbo].[tempchu];/* Sample load and unload using bcp */bcp.exe"[AdventureWorks2012].dbo.[tempchu]"out"C:\myscratch\tempchu.dat"-x-n"C:\myscratch\tempchu.xml"-T-Slocalhostbcp.exe"[AdventureWorks2012].dbo.[tempchu]"in"C:\myscratch\tempchu.dat"-n-T-Slocalhost/* Sample CSV data Rick Chu,1576 NW rightKim Chu,2363 NW leftBritney Chu,2367 NW up*/
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.