I want to create a query to list of all user defined stored procedures, excluding the ones that are system stored procedures, considering that:
There must be a property, or a flag somewhere since you can see the "System Stored Procedures" in a separate folder in SQL 2005. Does anyone know?
Edit: A combination of the suggestions below worked for me:
select *
from
sys.objects O LEFT OUTER JOIN
sys.extended_properties E ON O.object_id = E.major_id
WHERE
O.name IS NOT NULL
AND ISNULL(O.is_ms_shipped, 0) = 0
AND ISNULL(E.name, '') <> 'microsoft_database_tools_support'
AND O.type_desc = 'SQL_STORED_PROCEDURE'
ORDER BY O.name
-- Get list of possibly unused SPs (SQL 2008 only) SELECT p.name AS 'SP Name' -- Get list of all SPs in the current database FROM sys. procedures AS p WHERE p. is_ms_shipped = 0 EXCEPT SELECT p.name AS 'SP Name' -- Get list of all SPs from the current database FROM sys.
You should use something like this:
select * from sys.procedures where is_ms_shipped = 0
As you could guess, the key is in is_ms_shipped attribute (it exists in sys.objects view as well).
UPDATED. Initially missed your point about is_ms_shipped.
This is the code (condition) that Management Studio actually uses to retrieve a list of 'system stored procedures'
CAST(
case
when sp.is_ms_shipped = 1 then 1
when (
select
major_id
from
sys.extended_properties
where
major_id = sp.object_id and
minor_id = 0 and
class = 1 and
name = N''microsoft_database_tools_support'')
is not null then 1
else 0
end AS BIT) = 1
Here sp refers to sys.all_objects system view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With