Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Native output
- Native output is preferrable for SQL Server to SQL Server out->in operations. `-n` is for single byte (varchar) data.
- `-N` is for multi-byte characters (nvarchar)
- ```
- bcp "select top 100 * from {{db}}.{{schema}}.{{table}}" QUERYOUT {{table}}_sample.txt -S {{server1}} -T -n
- bcp "{{db}}.{{schema}}.{{table}}" OUT {{table}}.txt -S {{server1}} -T -n
- bcp "{{db}}.{{schema}}.{{table}}" IN {{table}}.txt -S {{server2}} -T -n -E
- ```
- ## For character output
- Character output is for plain-old-text files. `-c` means character. `-t` is the field separator, and if omitted is a tab.
- `-r` is the row separator. If your data has the field or row separators in it, watch out! BCP will give an invalid file
- format and go on like that's okay.
- ```
- bcp "select top 100 * from {{db}}.{{schema}}.{{table}}" QUERYOUT {{table}}_sample.txt -S {{server1}} -T -c -t "~|\t|~" -r ";;;;;\n"
- bcp "{{db}}.{{schema}}.{{table}}" OUT {{table}}.txt -S {{server1}} -T -c -t "~|\t|~" -r ";;;;;\n"
- bcp "{{db}}.{{schema}}.{{table}}" IN {{table}}.txt -S {{server2}} -T -c -t "~|\t|~" -r ";;;;;\n" -E
- ```
- ## To use a format file
- ```
- bcp "{{db}}.{{schema}}.{{table}}" format nul -S {{server1}} -T -N -f {{table}}.fmt
- ```
- ## To load a CSV (with header) with a format file
- `-F2` starts on line 2 (skips header)
- ```
- bcp "{{db}}.{{schema}}.{{table}}" IN {{file_path}}.csv -S {{server}} -f {{table}}.fmt -T -F2
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement