Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count all stored procedures in the SQL Server for a database?

Tags:

sql

sql-server

How can I count all stored procedures which are written by me in my database?

like image 756
NoviceToDotNet Avatar asked Jan 07 '11 18:01

NoviceToDotNet


People also ask

How can find execution count of stored procedure in SQL Server?

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.

How do I find the number of functions in a SQL Server database?

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.


7 Answers

select Count(*) from sys.procedures

And as Philip Kelley noted this is sql 2005 and up

like image 123
Conrad Frix Avatar answered Oct 01 '22 06:10

Conrad Frix


-- 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'
like image 27
Iyyappan Avatar answered Oct 01 '22 06:10

Iyyappan


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.

like image 25
Neil Knight Avatar answered Oct 01 '22 06:10

Neil Knight


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_%'
like image 41
phantomflash Avatar answered Oct 01 '22 06:10

phantomflash


SELECT COUNT(*)
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = 'PROCEDURE'
like image 39
Lamak Avatar answered Oct 01 '22 06:10

Lamak


select count(name)
from sys.objects
where type = 'P'
like image 37
Jason Avatar answered Oct 01 '22 04:10

Jason


select count(*)
from sysobjects
where xtype='P'
like image 33
Doliveras Avatar answered Oct 01 '22 05:10

Doliveras