bcp & bulk insert

2019-08-27  本文已影响0人  鲸鱼酱375

1.BCP and Bulk Insert

1.1 What are Bulk Operations?

1.2 Bulk Copy Program

bulk
BCP "SELECT TOP 100 BusinessEntityID, FirstName, LastName FROM AdventureWorks2017.Person.Person" QUERYOUT C:\cmd\Per.txt -c -T

1.1.2 操作符号 都要在一行里面写出来!!!!!

1.1.2.1 Data to a file from a table using OUT option

-T Trusted connection
-c Character data type for the output file

BCP AdventureWorks2012.HumanResources.Employee OUT C:\BulkOps\Emp.txt -c -T 

BCP "SELECT TOP 100 BusinessEntityID, FirstName, LastName 
FROM AdventureWorks2012.Person.Person" QUERYOUT C:\BulkOps\Per.txt -c -T -t,

BCP AdventureWorks2012.dbo.Per IN C:\Raj\BulkOps\Per.txt -c -T -t,

1.1.2.2 Creating a comma separated file using OUT option

-t specifying there is a column terminator or delimiter followed by delimiter value

-t, --in this case -t specifies there is a delimiter for column and (,) is the delimiter

BCP AdventureWorks2012.HumanResources.Employee OUT C:\OPFiles\Emp.txt -c -T -t, 

1.1.2.3 Creating a file using OUT option and error out put to another file

-e specifies that there is an error file followed by path for error file

BCP AdventureWorks2012.HumanResources.Employee OUT 
C:\OPFiles\Emp.txt -c -T -e C:\OPFiles\ErrorFile.txt

1.1.2.4 Creating a file using QUERYOUT option


BCP SELECT top 1000 FirstName, LastName from 
AdventureWorks2012.Person.Person QUERYOUT C:\BulkOps\Person.txt -c -T

others:

--File Location to be copied
--Data format -c/-N/-n/-w (-c Character, -N Unicode Native, -n Native, -w Unicode)
--Field Terminator -t
--Server info -S
--Login info -T/-U
--Hints ORDER, FIRETRIGGERS
--Ignore Identity Column values -E
--Batch Size -b value
--First Row start -F value
--Last Row -L value
--Error File -e File Path

1.3 Bulk Insert

bulk insert bulk_op
from 'c:\bulk_op\empinfo.txt'

1.4 Differences Between BCP & BI

diff

1.4.1 bulk insert

1.4.2 bcp

1.5 note

BCP AdventureWorks2012.HumanResources.Employee IN C:\Users\admin\Desktop\BulkOps\Employee.dat -c -t, -S localhost -T -h FIRE_TRIGGERS -E -b 100 -F 25 -e C:\Users\admin\Desktop\BulkOps\ErrorFile.txt

BCP AdventureWorks2012.dbo.Emp IN C:\Users\admin\Desktop\BulkOps\Employee.dat -c -t, -S localhost -T -h FIRE_TRIGGERS

BCP "SELECT P.BusinessEntityID, P.FirstName, P.LastName, E.BirthDate, E.MaritalStatus, E.Gender FROM AdventureWorks2012.Person.Person P JOIN AdventureWorks2012.HumanResources.Employee E ON E.BusinessEntityID = P.BusinessEntityID" QUERYOUT C:\Users\admin\Desktop\BulkOps\Emp_QO.txt -N -t, -T

BCP AdventureWorks2012.Person.Person OUT C:\Users\admin\Desktop\BulkOps\Employee.dat -c -t, -S localhost -T -h ORDER(FirstName)

--CSV, XLT, DAT, FMT, TXT
上一篇 下一篇

猜你喜欢

热点阅读