Database Table Sizes

This is a good query for quickly finding out general information about your table sizes in your specified database: USE [DBName] SELECT t.NAME AS TableName, s.Name AS SchemaName, p.ROWS AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, SUM(a.used_pages) * 8 AS UsedSpaceKB, (SUM(a.total_pages) – SUM(a.used_pages)) * 8 AS UnusedSpaceKB FROM sys.TABLES Continue Reading

List Foreign Keys, Parent and Referenced Columns

SELECT fk.name AS ForeignKey_Name, ob.name AS ParentTableName, col.name AS ParentColName, ob2.name AS ReferencedTableName, RCol.name AS ReferenceColName FROM sys.foreign_keys AS fk INNER JOIN sys.objects AS ob ON fk.parent_object_id = ob.object_id CROSS JOIN sys.objects AS ob2 INNER JOIN sys.foreign_key_columns AS fkc ON fk.object_id = fkc.constraint_object_id INNER JOIN sys.COLUMNS AS COL ON col.object_id Continue Reading