Technical Article

Generate BCP commands (sp_bcp)

,

This is an updated scripts with some useful modification for the script submitted by Seshu Kanuri

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_bcp]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_bcp]
GO
set quoted_identifier off
go
create procedure sp_bcp AS
BEGIN
/* The script below creates a stored procedure which returns bcp commands for all tables 
in the current database. You should change the servername (sqlserver) to the desired sql server
name and the sa password (password), to your sql server sa password.
you can also change the out file location (replace d:\ with the dsired drive and folder for the
output files). 
   Author : Seshu Kanuri, DBA, EB2B Commerce, Inc.
updated by karen ronen, DBA, ness technologies.  
*/if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_bcp]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_bcp]
GO
set quoted_identifier off
go
create procedure sp_bcp AS
BEGIN
declare @dbname varchar (50)
declare @sqlstr nvarchar(4000)
set @dbname=db_name()
set @sqlstr="select 'bcp '+" +"'"+ @dbname +"..'"+ '+name+'+  "' OUT d:\'"+'+name+'+ "'.txt -c -e d:\' " +   '+name+'+" '.err -S sqlserver -U sa -P password -t /t' as bcp_commands from sysobjects where type='U' order by name "
exec sp_executesql @sqlstr 

/* To run the script - Execute sp_bcp */end
go
set quoted_identifier on
go

Rate

5 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (1)

You rated this post out of 5. Change rating