devxlogo

Identifying Unused Tables with T-SQL

Identifying Unused Tables with T-SQL

You can identify unused Tables in the following way:

; with Unused (TableName , RowCount, DateCreated, DateModified)AS (SELECT unusedTable.name AS TableName,PS.row_count AS RowCount,unusedTable.create_date AS DateCreated,unusedTable.modify_date AS DateModifiedFROM sys.all_objects UnusedTableJOIN sys.dm_db_partition_stats PS ON OBJECT_NAME(PS.object_id)=unusedTable.nameWHERE unusedTable.type ='U'AND NOT EXISTS (SELECT OBJECT_IDFROM sys.dm_db_index_usage_statsWHERE OBJECT_ID = unusedTable.object_id ))SELECT TableName , RowCount, DateCreated, DateModifiedFROM UnusedORDER BY RowCount
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist