Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

Find Recently Modified Stored Procedures

From Wiki

Jump to: navigation, search

How can you easily find out which stored procedures have been changed in the last hour/week or whatever period you would like to use? In 2000 there was no easy way because refdate and crdate were identical in the sysobjects table.
SQL Server 2005 introduced sys.procedures, sys.procedures has the columns create_date and modify_date. The columns modify_date does change when you alter a procedures. Let us take a look at how this works


First create this stored procedure

  1. CREATE PROC prtest
  2. AS
  3. SELECT GETDATE()
  4. go


Now run this query, as you can see the dates are the same

  1. SELECT name,create_date,modify_date
  2. FROM sys.procedures
  3. WHERE name = 'prtest'
  4. go


Now change the procedure

  1. ALTER PROC prtest
  2. AS
  3. SELECT GETUTCDATE()
  4. go

When you run the same query from before you can see that the modify_date column is not the same as the create_date column anymore

  1. SELECT name,create_date,modify_date
  2. FROM sys.procedures
  3. WHERE name = 'prtest'
  4. go


Here is a query which returns all the procs that have been modified in the last 60 minutes

  1. SELECT name,create_date,modify_date,DATEDIFF(mi,modify_date,GETDATE()) AS ModifiedMinutesAgo
  2. FROM sys.procedures
  3. WHERE DATEDIFF(mi,modify_date,GETDATE())  < 60
  4. go


Contributed by: --SQLDenis 17:30, 17 September 2008 (GMT)


Part of SQL Server Admin Hacks

594 Rating: 0.0/5 (0 votes cast)