For more information about the parameters of the BCP tool, see books online.
This section describes how to use the following four examples: Export (out), import (in), query and export (queryout), and export and format (-f) files.
Example 1: export the sample databaseAdventureworksEntire tableCurrencyOr view, use SQL to connect
BCP adventureworks. Sales. Currency out c: \ currency1.txt - C - U "sa" - P "password" -- Connect using SQL
Example 2: connect with a trusted connection.
BCP adventureworks. Sales. Currency out c: \ currency1.txt - C - T -- Use trusted connection
Example 3: import data
BCP adventureworks. Sales. currency1 In C: \ currency1.txt - C - T
Or import 10-13 rows of the specified data
BCP adventureworks. Sales. currency1 In C: \ currency1.txt - C - F 10 - L 13 - T
Example 4: Use query to export data
BCP" Select Top 20 * From Adventureworks. Sales. Currency "queryout c: \ currency2.txt - F 10 - L 13 - C - U "sa" - P "password" - S "ip"
Or
BCP" Select Top 4 * From Adventureworks. Sales. Currency Where ID Not In ( Select Top 9 ID From Adventureworks. Sales. Currency "queryout c: \ currency2.txt - C - U "sa" - P "password" - S "ip"
Example 5: export a formatted file:
Exec Master .. xp_mongoshell ' BCP adventureworks. Sales. Currency format NUL-f c: \ currency_format1.fmt-c-t
Finally: The above is the BCP tool of the client, you can also use the BCP of the server from the client
Exec Master .. xp_mongoshell ' BCP "select top 20 * From adventureworks. Sales. Currency" queryout c: \ cur.txt-f 10-L 13-c-t