SQLTeam.com | Weblogs | Forums

Select top 10 Rows AND Table Name

Hi experts, I need to select the first 10 rowsin each tbale. The following does that, but I would like to return that table name as well.

Can that be done?
Thanks,

Select Top 10 * From dbo.Table1
Select Top 10 * From dbo.Tbale2
Select Top 10 * From dbo.Table3

Select Top (10) 'Table1' AS Table_Name, * From dbo.Table1
Select Top (10) 'Table2' AS Table_Name, * From dbo.Table2
Select Top (10) 'Table3' AS Table_Name, * From dbo.Table3

Yes but I have 62 tables. Looking for a way to select the name without having to paste it into my Select statement preferably. Thanks

Then generate the code to run:

SELECT 'SELECT ''' + name + ''' AS table_name, *
FROM [' + SCHEMA_NAME(schema_id) + '].[' + name + ']'
FROM sys.tables
ORDER BY name