BCP Bulk Data Import Export tool use Step _mssql

Source: Internet
Author: User

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 Code code 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 Code code as follows:
BCP AdventureWorks.sales.currency out c:currency1.txt-c-t--Using trusted connections

Example 3: Importing Data

Copy Code code as follows:
BCP AdventureWorks.sales.currency1 in C:currency1.txt-c-t

Or import the specified data row 10-13 rows

Copy Code code as follows:
BCP AdventureWorks.sales.currency1 in c:\currency1.txt-c-F 10-l 13-t


Example 4: Using a query to export

Copy Code code as follows:
BCP "SELECT top * from AdventureWorks.sales.currency" queryout C:\currency2.txt-F 10-l 13-c-U "sa"-P "password"-S "I P

Or

Copy Code code as follows:
BCP "SELECT top 4 *" AdventureWorks.sales.currency where ID is 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 format file:

Copy Code code 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 Code code as follows:
EXEC Master.. xp_cmdshell ' bcp ' select top * ' AdventureWorks.sales.currency ' queryout c:\cur.txt-F 10-l 13-c-T

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.