Tuesday 5 June 2012

sys.procedure in sql server


 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.


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
GO 
SELECT modify_date,name,create_date
FROM sys.procedures
ORDER BY modify_date DESC
GO
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
GO
SELECT modify_date,name,create_date
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%charindex%'
ORDER BY modify_date DESC
GO

No comments:

Post a Comment