SQL Server 2025 : bcp Utility2026/03/25 |
|
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 -C -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 2026-03-25 08:48:00.090 model 2003-04-08 09:13:36.390 msdb 2026-02-25 21:40:26.777 SampleDB 2026-03-24 10:38:26.657 SampleDB2 2026-03-24 10:38:53.230 (6 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 -u -c -t, -C -S localhost -U SA Password:
Starting copy...
3 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 11 Average : (272.73 rows per sec.)
[root@dlp ~]#
cat test.txt 00001,RedHat,Linux,2026-03-18 00002,Debian,Linux,2026-03-17 00003,Ubuntu,Linux,2026-03-17 # 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]
[-C code page specifier] [-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 or tokenfile]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values][-G Microsoft Entra ID Authentication]
[-h "load hints"] [-d database name]
[-Y[s|m|o] encrypt option][-u trust server certificate]
[-z enable vector data-type support]
[-H hostname in the certificate] [-J Server certificate]
|
| Sponsored Link |
|
|