How can I count all stored procedures which are written by me in my database?
The “sys. dm_exec_query_stats” view contains the column “total_worker_time”, which is the total number of microseconds that a given cached query plan has executed.
To get the list of all the functions in a database, you can use the transact SQL statement against the system objects like Sys. Objects, Information_Schema. Routines, syscomments or Sys. Sql_Modules.
select Count(*) from sys.procedures
And as Philip Kelley noted this is sql 2005 and up
-- Information about table --
SELECT * FROM sys.sysobjects WHERE xtype = 'U'
-- Information about Stored Procedure --
SELECT * FROM sys.sysobjects WHERE xtype = 'P'
-- Information about Functions --
SELECT * FROM sys.sysobjects WHERE xtype = 'FN'
-- Information about Views --
SELECT * FROM sys.sysobjects WHERE xtype = 'V'
To get the Stored Procedure count:
SELECT COUNT(*) SPCOUNT
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE='PROCEDURE'
or:
SELECT COUNT(*)
FROM sys.procedures
or:
SELECT COUNT(*)
FROM sys.sysobjects
WHERE xtype = 'P'
Hope one of these help.
As the OP pointed out in a comment, all of the earlier answers are wrong, because they include system procedures. He specifically asked for procedures that were "written by me" -- and later clarified in another comment "other than the system procedure, written by me or anybody working on that data base."
So to exclude system procedures, the only differentiating field I see in sys.procedures is the name. Therefore you need to add a WHERE clause to any of the other answers, like this:
select count(*) from sys.procedures
where name not like 'sp_%'
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = 'PROCEDURE'
select count(name)
from sys.objects
where type = 'P'
select count(*)
from sysobjects
where xtype='P'
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