I have a database with 69 tables and I want to select only the first three records of each table.
I can do it per table with:
SELECT TOP 3 *
Here you have:
DECLARE @sql VARCHAR(MAX)=''; SELECT @sql=@sql+'SELECT TOP 3 * FROM '+'['+SCHEMA_NAME(schema_id)+'].['+name+']'+';' FROM sys.tables EXEC(@sql)
exec sp_MSforeachtable 'select top 3 * from ?'