I want to generate a script which will give me an "insert" query with data from my existing database, but only top 1000 rows ordered by ID from each table. I tried to generate a query for a single table by using "Generate scripts..." which is located in Management Studio (MyDatabaseName -> Tasks -> Generate scripts...) and then I wrote a simple function in C# which cut the data to 1000 first rows but it's not a good idea when you have hundreds of tables
List<string> script = File.ReadLines(@"script.sql").Take(1000).ToList();
File.WriteAllLines(@"top1000.sql", script);
The script below will generate statements for all tables in a source database to have 1000 random records copied to another empty database.
Note that a "select * insert into ..." statement will only work if the target table doesn't already exist.
The ORDER BY uses the primary key of the table.
If it has one.