-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_TableList.sql
More file actions
25 lines (23 loc) · 897 Bytes
/
Copy path_TableList.sql
File metadata and controls
25 lines (23 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- Pckgd
-- Title: Table List
-- Description: Provides a list of the tables in the database and some basic information about them.
-- Updates from: GitHub/TenthPres/TouchPointScripts/_TableList.sql
-- Author: James at Tenth
SELECT
SCHEMA_NAME(t.schema_id) AS SchemaName,
t.NAME AS TableName,
COUNT(DISTINCT c.column_id) AS Cols,
CONVERT(INT, p.[Rows]) AS Recs
FROM sys.tables t
INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
JOIN sys.columns c ON t.object_id = c.object_id
WHERE
t.NAME NOT LIKE 'dt%' AND
i.OBJECT_ID > 255 AND
i.index_id <= 1
GROUP BY
SCHEMA_NAME(t.schema_id), t.NAME, i.object_id, i.index_id, i.name, p.[Rows]
ORDER BY
object_name(i.object_id);