How to render all records from all tables in the sample database, below query is returning all the tables record counts. but i want all records from all tables in the sample database.
SELECT TableName = o.name,
Rows = max(i.rows)
FROM sysobjects o
INNER JOIN sysindexes i
ON o.id = i.id
GROUP BY o.name
ORDER BY Rows DESC
You can use an undocumented(*) stored procedure to run a query against each table in the database:
This will return one result set for each table. If you want the table name as a separate column:
There’s no easy way to get just a single result set since, in general, the columns of all of the tables in a database will not be compatible with each other.
(*) Hopefully, the danger here is obvious. It’s undocumented, so it’s possible that it will go away or change based on any servicing operations applied to SQL Server. On the other hand, I doubt they will ever remove it, and it doesn’t have any special magic inside. For belt and braces, you might want to copy the procedure into your own database under a different name, and then you can rely on it not being changed.