Created
November 29, 2012 14:12
-
-
Save lionofdezert/4169335 to your computer and use it in GitHub Desktop.
Script to get list of stored procedures which contains tables but without non clusterd indexes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Script By: Aasim Abdullah for http://connectsql.blogspot.com | |
Purpose: To get list of stored procedures which contains tables but without non clusterd indexes | |
*/ | |
SELECT * | |
FROM ( SELECT SCHEMA_NAME(schema_id) + '.' + NAME AS ProcedureName, | |
SUBSTRING(( SELECT DISTINCT | |
', ' + OBJDEP.NAME | |
FROM sysdepends | |
INNER JOIN sys.objects OBJ ON sysdepends.ID = OBJ.OBJECT_ID | |
INNER JOIN sys.objects OBJDEP ON sysdepends.DEPID = OBJDEP.OBJECT_ID | |
WHERE obj.type = 'P' | |
AND Objdep.type IN ( 'U', 'V' ) --view and tables | |
AND EXISTS ( SELECT 1 | |
FROM sys.indexes | |
WHERE type = 2 | |
AND Objdep.OBJECT_ID = OBJECT_ID ) | |
AND sysdepends.id = procs.object_id | |
FOR | |
XML PATH('') ), 2, 8000) AS TablesWithNCIndexes, | |
SUBSTRING(( SELECT DISTINCT | |
', ' + OBJDEP.NAME | |
FROM sysdepends | |
INNER JOIN sys.objects OBJ ON sysdepends.ID = OBJ.OBJECT_ID | |
INNER JOIN sys.objects OBJDEP ON sysdepends.DEPID = OBJDEP.OBJECT_ID | |
WHERE obj.type = 'P' | |
AND Objdep.type IN ( 'U', 'V' ) --view and tables | |
AND NOT EXISTS ( SELECT 1 | |
FROM sys.indexes | |
WHERE type = 2 | |
AND Objdep.OBJECT_ID = OBJECT_ID ) | |
AND sysdepends.id = procs.object_id | |
FOR | |
XML PATH('') ), 2, 8000) AS TablesWithOutNCIndexes | |
FROM sys.procedures procs | |
WHERE procs.name NOT LIKE 'sp_%' --skip system stored procedures | |
) InnerTab | |
WHERE TablesWithOutNCIndexes IS NOT NULL | |
OR TablesWithNCIndexes IS NOT NULL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment