What is BCP in MSSQL
The Bulk Copy Program (BCP) is a
command-line utility that ships with Microsoft SQL Server. With BCP, you can
import and export large amounts of data in and out of SQL Server databases
quickly and easily. Any DBA who has utilized this functionality will agree that
BCP is an essential tool.
You access the BCP utility from the command prompt. Here's the simple syntax:
bcp {dbtable | query} {in | out | queryout | format} datafile
[-n native type] [-c character type] [-S server name] [-U username]
[-P password] [-T trusted connection]
For import :
C:\Users\suresh>bcp db_aaaa.dbo.tablename in Drive:\import.txt" -S localhost -T -c
For Export :
You access the BCP utility from the command prompt. Here's the simple syntax:
bcp {dbtable | query} {in | out | queryout | format} datafile
[-n native type] [-c character type] [-S server name] [-U username]
[-P password] [-T trusted connection]
The command example I'm going to use starts with bcp
followed by a fully qualified table name (database name, table or object owner,
table or object name). For example, if you want to export the table, as part of the dbo group from the
db_aaaa database, you supply the full table db_aaaa.dbo.tablename Next, you use
an in or out argument to specify whether you want BCP to copy data into or out
of a database. You then specify the location of the data-file on your database
server.
C:\Users\suresh>bcp
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] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection][-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"] [-x generate xml format file]
[-d database name] [-K application intent]
C:\Users\suresh>bcp db_aaaa.dbo.tablename in Drive:\import.txt" -S localhost -T -c
For Export :
C:\Users\suresh>bcp "select * from
db_aaaa.dbo.tablename" queryout "Drive:\export.txt" -S localhost -T
-c
nic blog. it will very helpful.
ReplyDeleteThank you ashish
Delete