Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. ## Native output
  2.  
  3. Native output is preferrable for SQL Server to SQL Server out->in operations. `-n` is for single byte (varchar) data.
  4. `-N` is for multi-byte characters (nvarchar)
  5. ```
  6. bcp "select top 100 * from {{db}}.{{schema}}.{{table}}" QUERYOUT {{table}}_sample.txt -S {{server1}} -T -n
  7. bcp "{{db}}.{{schema}}.{{table}}" OUT {{table}}.txt -S {{server1}} -T -n
  8. bcp "{{db}}.{{schema}}.{{table}}" IN {{table}}.txt -S {{server2}} -T -n -E
  9. ```
  10.  
  11. ## For character output
  12.  
  13. Character output is for plain-old-text files. `-c` means character. `-t` is the field separator, and if omitted is a tab.
  14. `-r` is the row separator. If your data has the field or row separators in it, watch out! BCP will give an invalid file
  15. format and go on like that's okay.
  16. ```
  17. bcp "select top 100 * from {{db}}.{{schema}}.{{table}}" QUERYOUT {{table}}_sample.txt -S {{server1}} -T -c -t "~|\t|~" -r ";;;;;\n"
  18. bcp "{{db}}.{{schema}}.{{table}}" OUT {{table}}.txt -S {{server1}} -T -c -t "~|\t|~" -r ";;;;;\n"
  19. bcp "{{db}}.{{schema}}.{{table}}" IN {{table}}.txt -S {{server2}} -T -c -t "~|\t|~" -r ";;;;;\n" -E
  20. ```
  21.  
  22. ## To use a format file
  23. ```
  24. bcp "{{db}}.{{schema}}.{{table}}" format nul -S {{server1}} -T -N -f {{table}}.fmt
  25. ```
  26.  
  27. ## To load a CSV (with header) with a format file
  28. `-F2` starts on line 2 (skips header)
  29. ```
  30. bcp "{{db}}.{{schema}}.{{table}}" IN {{file_path}}.csv -S {{server}} -f {{table}}.fmt -T -F2
  31. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement