简体   繁体   中英

getting schema + first 100 records from every table in a db

i have a large sql server db, and i want to get the schema (all tables/triggers/sprocs), i'm pretty sure that's easy.

but the tough part is that i want to get 100 records from each table. it's a huge db on a remote server and i can't develop locally without a mockup copy.

thanks for your help!

To get the schema, basically just select everything from the sys.objects catalog view:

SELECT * FROM sys.objects

For the data: you could use the undocumented (but extremely helpful) stored procedure sp_MSForEachTable for that purpose:

exec sp_MSforeachtable 'select top 100 * from ? '

I would create a cursor with sys.objects to get the user defined tables and populate the new database with select query of top 100 rows.

Make sure you have (NOLOCK) hint to your query, so that it can avoid locks

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