Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I output a table to a txt file using tsql?

How do I output a table to a txt file using tsql? I don't want to use DTS or SSIS in this instance.

like image 455
Craig Schwarze Avatar asked Feb 08 '10 23:02

Craig Schwarze


1 Answers

BCP

bcp MyDb.MySchema.Mytable out myTable.dat -T -c
  • out can be replace with queryout if using an sql query, or in if loading data in.
  • -T windows authentication, replace with -u and -p for sql auth
  • -c outputs as text instead of binary
  • -r is the row terminator option
  • -t os tje field terminator option
  • -S to specify a non default server

thats about all the really usefull options for exporting i think.

like image 90
Paul Creasey Avatar answered Oct 05 '22 00:10

Paul Creasey