May 12, 2008 at 12:06 pm
Hi all.
I have the following scripts which works for the pubs db...
select 'bcp pubs..' + name + ' out ' + name + '.txt' + '-c -T' from pubs..sysobjects where type = 'U' order by name
It generates the following which I can output to a batch file and run from the command prompt:
bcp pubs..authors out authors.txt -c -T
bcp pubs..discounts out discounts.txt -c -T
etc.
for all the tables in pubs.
Now what I'd like is to generalize this so that all the tables for all the created databases will have a corresponding bcp output. Any suggestions? I'd like to generate an output generically like so:
bcp [database name]..[table1] out [database+table1].txt -c -T
bcp [database name]..[table2] out [database+table2].txt -c -T
etc.
I'm having a devil of a time passing the parameters properly.
May 12, 2008 at 10:04 pm
Google for ...
sp_MSForEachDB
sp_MSForEachTable
--Jeff Moden
Change is inevitable... Change for the better is not.
May 13, 2008 at 8:10 am
Thanks Jeff, enormously helpful. Love all the "undocumented" procedures out there, like uncovering buried treasure.
Gaby
May 13, 2008 at 8:39 am
You'll also find a lot of folks that suggest not using them because Microsoft could change them at any time... Heck, they do that with documented features :hehe:
--Jeff Moden
Change is inevitable... Change for the better is not.
November 26, 2008 at 2:14 pm
Did you get a script to work for this? I am wanting to use a script to bcp out the data from all the tables in the database without running them one at a time. I would really appreciate it if you did get one to run if you could post the script.
Thanks!!!
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply