Click here to Skip to main content
13,197,767 members (40,470 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked
Posted 18 Mar 2012

SQL Server: Search Stored Procedure Create/Modify Date or Text using T-SQL

, 18 Mar 2012
Rate this:
Please Sign up or sign in to vote.
How to search Stored Procedure create/modify date or text using TSQL

SQL Server Management Studio (SSMS) is a great tool for managing instances of your SQL Server databases. Sometimes, though, the fastest way to retrieve information you are looking for isn’t through the SSMS GUI, but through direct SQL queries.

Case in point: If you want to search for specific information about stored procedures in your database. Rather than look one by one through the code, you can query the SQL Server sys.objects and sys.procedures tables to find exactly what you are looking for.

To search for stored procedures that were created or modified on a specific date, you can directly search either the sys.objects and sys.procedures tables.

Note: I have written and tested the example queries below in SQL Server 2005 and SQL Server 2008. The syntax for earlier or later platforms may vary. For example, SQL Server 2000 does not support the sys.objects and sys.procedures tables.

Using the sys.objects Table

To query the sys.objects table and order by the most recently modified stored procedures, use the following syntax:

USE DatabaseName
SELECT modify_date, name, create_date
FROM sys.objects
WHERE type = 'P'
ORDER BY Modify_date desc

It’s important in this example to remember to include the where clause filter for type=p so that only stored procedures are returned.

For reference purposes, here are the types that the sys.objects table holds:

TypeType Meaning

Using the sys.procedures Table

You can run exactly the same query against the sys.procedures table. Since this table is dedicated to storing detailed information about your database’s stored procedures, you do not need to include a type filter with your query.

USE DatabaseName
SELECT modify_date,name,create_date
FROM sys.procedures
ORDER BY modify_date DESC

As you can see, the sys.procedures table is quite useful, but you can use it to query more than just the name and create/modify dates.

For example, you can query the sys.prodedures table for stored procedures that contain specific text. This is really a handy function that can be useful if you are combing through an unfamiliar database or want to find very specific code quickly. You can even return the text of the procedure directly in your query so that you can quickly analyze each of the returned results quickly without having to find and open the procedure in SSMS.

Here is an example query that filters stored procedures to return only ones that contain the SQL CHARINDEX function:

USE DatabaseName
SELECT modify_date,name,create_date
FROM sys.procedures
ORDER BY modify_date DESC


As you can see, SQL Server offers many useful functions for quickly searching through information in your database. Although SSMS offers a friendly and easy to use UI, it is often more efficient to query information about stored procedures in your database directly via system tales such as the sys.objects and sys.procedures tables.

Similar functionality exists for other SQL Server system objects such as views, tables, or functions. I hope to cover these and more in future articles.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Justin Cooney
Software Developer
Canada Canada
I've been professionally programming since 1997. I like to blog about programming issues and/or interesting facts. I currently focus on ASP.NET, MS SQL Server, HTML5, JavaScript, JQuery, and MS Outlook development.

You may also be interested in...


Comments and Discussions

GeneralVery Useful Pin
m_irfan28-Mar-12 21:46
memberm_irfan28-Mar-12 21:46 
GeneralRe: Very Useful Pin
Justin Cooney1-Apr-12 7:07
memberJustin Cooney1-Apr-12 7:07 
GeneralMy vote of 5 Pin
ii_noname_ii19-Mar-12 4:19
memberii_noname_ii19-Mar-12 4:19 
GeneralRe: My vote of 5 Pin
Justin Cooney19-Mar-12 8:39
memberJustin Cooney19-Mar-12 8:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171020.1 | Last Updated 18 Mar 2012
Article Copyright 2012 by Justin Cooney
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid