This is mainly about the use of four examples: export (out), import (in), query Export (queryout), export format (-f) files.
Example 1: Show sample database AdventureWorks entire table currency or view, using SQL connection
Copy CodeThe code is as follows: bcp AdventureWorks.sales.currency out c:\currency1.txt-c-u "sa"-P "password"--Use SQL connection
Example 2: ibid., using trusted connections
Copy CodeThe code is as follows: bcp AdventureWorks.sales.currency out c:currency1.txt-c-t--Using trusted connections
Example 3: Importing Data
Copy CodeThe code is as follows: bcp AdventureWorks.sales.currency1 in c:currency1.txt-c-t
Or import the specified data row 10-13 rows
Copy CodeThe code is as follows: bcp AdventureWorks.sales.currency1 in c:\currency1.txt-c-F 10-l 13-t
Example 4: Using a query to export
Copy CodeThe code is as follows: BCP "SELECT top * from AdventureWorks.sales.currency" queryout C:\currency2.txt-F 10-l 13-c-U "sa"-P "password" -S "IP"
Or
Copy CodeThe code is as follows: BCP "SELECT top 4 *" AdventureWorks.sales.currency where ID is not in (select Top 9 ID from AdventureWorks.sales.cur Rency "Queryout c:\currency2.txt-c-U" sa "-P" password "-S" IP "
Example 5: Export a format file:
Copy CodeThe code is as follows: EXEC master. xp_cmdshell ' bcp AdventureWorks.sales.currency format nul-f c:\currency_format1.fmt-c-T
Finally: Using the client's bcp tool, you can also use server-side bcp from the client
Copy CodeThe code is as follows: EXEC master. xp_cmdshell ' bcp ' select top * ' AdventureWorks.sales.currency ' queryout c:\cur.txt-F 10-l 13-c-T