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
精彩评论