How can I count all stored procedures which are written by me in my database?
-
possible duplicate of [Query to list SQL Server stored procedures along with lines of code for each procedure](http://stackoverflow.com/questions/291574/query-to-list-sql-server-stored-procedures-along-with-lines-of-code-for-each-proc) – Neil Knight Jan 07 '11 at 18:53
8 Answers
select Count(*) from sys.procedures
And as Philip Kelley noted this is sql 2005 and up

- 51,984
- 12
- 96
- 155
-- 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'

- 41,277
- 16
- 94
- 144

- 171
- 1
- 5
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.

- 47,437
- 25
- 129
- 188
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_%'

- 114
- 1
- 4
-
SELECT count(*) FROM sys.procedures WHERE SUBSTRING([name], 1, 3) <> 'sp_' for SQL 2019, SSMS 19 – Marc Roussel Oct 12 '22 at 14:16
-
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = 'PROCEDURE'

- 69,480
- 12
- 108
- 116
-
This gives a count including both system and mine written stored procedure, i want to know count for my own written stored procedure only. – NoviceToDotNet Jan 07 '11 at 18:47
-
-
@NoviceToDotNet When you say "mine written", are you talking about the procedures written only by your user?, or any user? – Lamak Jan 07 '11 at 18:50
-
other then the system procedure, witten by me or any body working on that data base – NoviceToDotNet Jan 07 '11 at 18:53
-
1
This will give you the count of tables and stored procedures.
SELECT
CASE TYPE
WHEN 'U'
THEN 'User Defined Tables'
WHEN 'S'
THEN 'System Tables'
WHEN 'IT'
THEN 'Internal Tables'
WHEN 'P'
THEN 'Stored Procedures'
WHEN 'PC'
THEN 'CLR Stored Procedures'
WHEN 'X'
THEN 'Extended Stored Procedures'
END,
COUNT(*)
FROM SYS.OBJECTS
WHERE TYPE IN ('U', 'P', 'PC', 'S', 'IT', 'X')
GROUP BY TYPE
You can find in sys.objects
all types of objects in the database. You will have to run this query on each of your databases to see the count of objects.

- 7,102
- 69
- 48
- 77

- 1
- 1