CentOS Stream 8
Sponsored Link

SQL Server 2019 : bcp Utility2021/05/30

 
It's possible to import or export data between an instance and a file in a specified format with bcp (bulk copy program) utility.
[1] To use [bcp] command which is included in [mssql-tools] package, it's possible to copy data.
[root@dlp ~]#
sqlcmd -S localhost -U SA -Q 'select name,create_date from sys.databases'

Password:
name                         create_date
---------------------------- -----------------------
master                       2003-04-08 09:13:36.390
tempdb                       2021-05-28 02:23:50.063
model                        2003-04-08 09:13:36.390
msdb                         2021-03-22 18:49:30.403
SampleDB                     2021-05-28 01:36:41.637
SampleDB2                    2021-05-28 01:57:46.577
TestDB_DailyJob              2021-05-28 02:24:21.970

(7 rows affected)

# export data from [Sample_Table] in [SampleDB] to [test.txt] with character data type

[root@dlp ~]#
bcp SampleDB.dbo.Sample_Table out test.txt -c -t, -S localhost -U SA

Password:
Starting copy...

2 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 2      Average : (1000.0 rows per sec.)

[root@dlp ~]#
cat test.txt

00001,CentOS,Linux,2021-05-30
00002,RedHat,Linux,2021-05-30
# for other options

[root@dlp ~]#
bcp -h

usage: bcp {dbtable | query} {in | out | queryout | format} datafile
  [-m maxerrors]            [-f formatfile]          [-e errfile]
  [-F firstrow]             [-L lastrow]             [-b batchsize]
  [-n native type]          [-c character type]      [-w wide character type]
  [-N keep non-text native] [-q quoted identifier]
  [-t field terminator]     [-r row terminator]
  [-a packetsize]           [-K application intent]
  [-S server name or DSN if -D provided]             [-D treat -S as DSN]
  [-U username]             [-P password]
  [-T trusted connection]   [-v version]             [-R regional enable]
  [-k keep null values]     [-E keep identity values]
  [-h "load hints"]         [-d database name]
Matched Content