Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I best take a sql dump with contents where you can see pk and fk

9 views
Skip to first unread message

Tony Johansson

unread,
Jul 16, 2012, 7:59:12 AM7/16/12
to
Hello!

I need to extract a sql dump from several tables where I can see the contens
and primary key and foreign key

//Tony

Erland Sommarskog

unread,
Jul 16, 2012, 5:54:37 PM7/16/12
to
Tony Johansson (johansson...@telia.com) writes:
> I need to extract a sql dump from several tables where I can see the
> contens and primary key and foreign key

SELECT *? Or do you want the "dump" in any special format? Can you
be more specific?

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Tony Johansson

unread,
Jul 16, 2012, 6:01:57 PM7/16/12
to
I want to get the name of the columns, the primary key and foreign key and
the contents.
I want all this output to be stored in a file.
I can do select * but can I redirect the output to a file.

//Tony

"Erland Sommarskog" <esq...@sommarskog.se> skrev i meddelandet
news:XnsA092F33A6...@127.0.0.1...

Erland Sommarskog

unread,
Jul 16, 2012, 6:07:06 PM7/16/12
to
Tony Johansson (johansson...@telia.com) writes:
> I want to get the name of the columns, the primary key and foreign key and
> the contents.
> I want all this output to be stored in a file.
> I can do select * but can I redirect the output to a file.

You can save the output window. You can right-click in the query window
and select Results To->File. There is also BCP and SQLCMD if you want to
automate the operation.

For tables and columns you can script the tables, and choose to script
to file.

Bob Barrows

unread,
Jul 16, 2012, 7:35:23 PM7/16/12
to
Still not enough specific information. How do you intend that the primary
and foreign keys be stored in the file? As a separate resultset? Show us
what you want to see in the file given a 3-colomn table with three rows, a
primary key on the first column and a foreign key on the third. Exactly
what will the file contain. Will it be a text file? If so, show us the text.

rja.ca...@gmail.com

unread,
Jul 17, 2012, 9:14:31 AM7/17/12
to
If you have SQL Server 2005 or later, then in Management Studio
you can probably "Export" data by right-clicking on the database
name. CSV or Microsoft Excel may be useful external data formats
when you're getting started with this. As far as I recall,
you can also move smoothly from this into SSIS for a job that
you can re-run on demand for multiple tables, but some maniac
persuaded the braindead management here to have SSIS removed
from all of our servers, presumably in order to stop employees
acquiring skills that other employers that pay better will want.
Of course, this takes down data import and export in
Management Studio, as well.

BCP is a very, very old tool now, and, in my experience,
is cranky. And I have a lot of experience, or it feels that way.
0 new messages