-- To fetch the number of records in a table
SELECT ss.name AS [schema],
Object_name(si.id) AS TableName,
Max(si.rowcnt) AS EstimatedRows
FROM dbo.sysindexes si
INNER JOIN sys.tables st
ON st.object_id = si.id
INNER JOIN sys.schemas ss
ON ss.schema_id = st.schema_id
WHERE indid < 2 -- clustered index or table entry
AND Objectproperty(si.id, 'IsUserTable') = 1
AND Objectproperty(si.id, 'IsMSShipped') = 0
AND Permissions(id) != 0 -- User must have at least some privileges on the object.
AND Object_name(si.id) LIKE '%Table Name%'
GROUP BY Object_name(si.id),
ss.name
ORDER BY 2
No comments:
Post a Comment