Search latest modified SP and View with its text in SQL Server 2008/2005

Today I have seen interesting question in one forum that how can I find modified Stored Procedure and Views after certain date with its text. Question is really interesting but the answer is really very small T-SQL.
If you use Sys.Objects, you can get list of all available objects in your database. Sys.Object has much important information about that object along with “Modify_Date” but this system view doesn’t contain text of those objects.
Well, in this scenario Object_Defination method comes to rescue us. If you pass Object’s ID in Object_Defination method, it will return Text for that object. So now let me show you short T-SQL for this task.
select name,OBJECT_DEFINITION(object_id),modify_date from sys.objects
where [type] in (‘V’,‘p’)  and convert(varchar,modify_date,112)>‘20090601’



Reference: Ritesh Shah
http://www.sqlhub.com
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of
http://www.SQLHub.com
Advertisements

2 Responses to “Search latest modified SP and View with its text in SQL Server 2008/2005”

  1. Madhivanan Says:

    You dont need to convert the date to varchar in the WHERE clausehttp://sqlblogcasts.com/blogs/madhivanan

  2. Ritesh Shah Says:

    yes, you are right. it will work without converting date too


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: