Guy Guy - 8 months ago 33
SQL Question

Print first 10 entries from each table in SQL Server database with empty lines between tables

I can open each table and do

select top 10 * from table_name
for each table and copy-paste results to Notepad. How can I automate it to have for each table print first 10 rows, followed by empty line in one output window?


This will form a statement to print first 10 rows of each table. Execute it for the desired output.

select 'Select Top 10 * From ' + SCHEMA_NAME(schema_id) + '.' + name 
from sys.objects 
where type = 'U'

Follow this method to get the desired output to one file: Is there any straightforward way to output text files (or CSV) from SQL Server?
Briefly: Tools-> Options-> Query results->results to text