bcp between utility can specify the format in Microsoft SQL Server instance and user data files bulk copy data. Use bcp utility can be a lot of new rows into SQL Server tables or export table data to the data file.
You need to download: https: //www.microsoft.com/zh-CN/download/details.aspx id = 56567?
https://docs.microsoft.com/zh-cn/sql/tools/bcp-utility?view=sql-server-2017
1. Use the command line
- export the whole table (OUT)
. BCP database name .dbo table name out c: \ currency.txt -S "database instance" -U "user" -P "password" -c
. BCP database name .dbo table name out c: \ currency.txt -S "database instance" -U "user" -P "password" -c
- Use SQL statements to export (queryout)
BCP "database name .dbo the SELECT * from table name." Queryout c: \ database instance currency.txt -S -U "user" -P "password" -c
- set the field separator and row delimiter (-c -t "," -r " \ n"), and so please do not want to enter the field types used together with -c
bcp "select * from .dbo database table name." queryout c: \ currency .txt -S database instance -U "user" -P "password" -C -t "," -R & lt "\ n-"
- Specifies the number of rows per batch imported data, each specified network data sent or received by the server the number of bytes packet (-k -b5000 -a65535)
BCP. "database name .dbo the SELECT * from table name" queryout c: \ currency.txt -S database instance -U "user" -P "password" -c - t "," -r "\ n " -k -b5000 -a65535
BCP "database name .dbo the SELECT * from table name." Queryout c: \ database instance currency.txt -S -U "user" -P "password" -c
- set the field separator and row delimiter (-c -t "," -r " \ n"), and so please do not want to enter the field types used together with -c
bcp "select * from .dbo database table name." queryout c: \ currency .txt -S database instance -U "user" -P "password" -C -t "," -R & lt "\ n-"
- Specifies the number of rows per batch imported data, each specified network data sent or received by the server the number of bytes packet (-k -b5000 -a65535)
BCP. "database name .dbo the SELECT * from table name" queryout c: \ currency.txt -S database instance -U "user" -P "password" -c - t "," -r "\ n " -k -b5000 -a65535
2. - executed on SQL SERVER Query Analyzer (EXEC master..xp_cmdshell)
- allows you to configure advanced options
EXEC master.sys.sp_configure 'Show advanced Options', 1
- reconfiguring
RECONFIGURE
- Enable the xp_cmdshell
EXEC master.sys.sp_configure 'the xp_cmdshell', 1
- reconfiguring
RECONFIGURE
EXEC master.sys.sp_configure 'Show advanced Options', 1
- reconfiguring
RECONFIGURE
- Enable the xp_cmdshell
EXEC master.sys.sp_configure 'the xp_cmdshell', 1
- reconfiguring
RECONFIGURE
EXEC master..xp_cmdshell 'bcp "select * from the database name .dbo table name." Queryout c: \ database instance currency.txt -S -U "user" -P "password" -c'
- the SQL statement generates a .sql file, and then call
- Note: The file path of the folder middle name can not have spaces
exec master..xp_cmdshell 'osql -S database instance -U user -P password -i C: \ cmdshellTest. SQL '
- import data into currency table
EXEC master..xp_cmdshell' bcp .dbo database table name in c: \ currency.txt -c -T ' .
- Import Data also may be used to select options and -L -F rows imported data.
EXEC master..xp_cmdshell 'bcp .dbo database table name in c:. \ Currency.txt -c -F 10 -L 13 -T'