views:

582

answers:

3

A consultant employed by my client has asked for an export of the the first n rows (approx 30 or 40) of all the tables in one of our SQL Server 2000 databases in csv format, including column names on the first row. The database has about 100 tables so I don't want to do this manually.

Can anyone recommend a script, tool or other approach that can do this quickly?

+1  A: 

You could potentially use the DTS (Data Transformation Services) of SQL Server 2000 and just export everything into an Excel sheet, no?

Marc

marc_s
Duh, that's undoubtedly the simplest solution. I was thinking that I'd need to script the csv export (which can only be done one table at a time) but going via an xls will be fine enough
Cruachan
<hehe> you can't see the obvious solution for the sea of tools available, eh? ;-)
marc_s
+2  A: 

Try this from enterprise manager

EXEC sp_MSForEachTable 'SELECT top 30 * from ?'

This will give you the top 30 records from each table in the current database. You can output the results to a text file

Conrad
+1 as although doesn't solve the problem (column titles in export) it's useful
Cruachan
Oh yes it does! If you configure Query Analyzer to get your results as text (Ctrl + T) instead of in a grid you will get the column titles. Try it
Conrad
+1  A: 

The first thirty rows would be useless if they aren't the related rows. If he isn't going to use them as test data (and he can't if the customer table has different customer ids in it's first 30 rows as the orders table), then why not just give him the schema?

Also be wary of providing real data to someone to use for development purposes.

HLGEM
Oh yes normally absolutely true, but in this case the consultant is part of the same (large) organisation albeit a different company, so security issues don't arise. It's also one of those political circumstances where the direct request overrides my normal judgement.
Cruachan