简体   繁体   中英

SQL Server whole database csv export

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?

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

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

Marc

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM