I usually run following script to check if any stored procedure was deployed on live server without proper authorization in last 7 days. If SQL Server suddenly start behaving in un-expectable behavior and if stored procedure were changed recently, following script can be used to check recently modified stored procedure. If stored procedure was created but never modified afterwards modified date and create date for that stored procedure are same.
SELECT name
FROM sys.objects
WHERE type = 'P'
AND DATEDIFF(D,modify_date, GETDATE()) < 7
----Change 7 to any other day value
Following script will provide name of all the stored procedure which were created in last 7 days, they may or may not be modified after that.
SELECT name
FROM sys.objects
WHERE type = 'P'
AND DATEDIFF(D,create_date, GETDATE()) < 7
----Change 7 to any other day value.
Date condition in above script can be adjusted to retrieve required data.
Reference : Pinal Dave (http://blog.SQLAuthority.com)





can you show also the host name of the machine who last modify it?
Hi
Is there any way to find out who has modified the stored procdure
Srinivas
There’s an error in your queries.
The line:
AND DATEDIFF(D,modify_date, GETDATE()) > 7
should be:
AND DATEDIFF(D,modify_date, GETDATE()) < 7
Same with the create_date query. Your query checks modifications/creations MORE than 7 days old.
Thanks for correction.
Beyond finding out about procs changed, when; how do I tell the last date, value and who modified a database setting such as “Read_Committed_Snapshot”?
I know I can test to see the current value with “is_read_committed_snapshot_on” from sys.databases but I need to know when the setting was changed and what value/whom set this type of property?
How much info can I get? how?
What events in SQL such as Update Statistics could turn this setting off without user intervention or user knowledge? How, separately perhaps, would I also audit such events/changes?
Thanks
[...] Aug 10th, 2007 by pinaldave This post is second part of my previous post about SQL SERVER – 2005 – List All Stored Procedure Modified in Last N Days [...]
Thank you for the query…
I need to add serial number to the record extracted from SQL server 2000. Is there any way to have my own set of serial number generated along with the query.
ex:
1 suresh 23
2 samuel 39
or
Please suggest….
Thank you for the query…
I need to add serial number to the record extracted from SQL server 2000. Is there any way to have my own set of serial number generated along with the query.
ex:
1 suresh 23
2 samuel 39
or
Please suggest….
Hi Suresh
Please try this query
Select (ROW_NUMBER() OVER ( Order By Height)) as MyRowNumber , Height, CorrectedHeight from Results
// Gandhi
Skalar –
Agaram Instruments
Chennai
THATS Good One thanks
Thanks Pinal
good!
thanks , very helpful ^^
is there a query to know the person who has made the change.. ie, if there has been a change in the sp / view / table, how to find who has done that change.
and what to display tables?
very nice. I got my doubts cleared through this.thanks a lot
Thank you so much, viewing the records for the last 7 days was the last task to complete my online application and I just want to say thanks for making it so easy.
Hi PinalDave,
i have find an interesting proc on web for some related task that you are doing here, here is location:
http://searchsqlserver.techtarget.com/searchSQLServer/downloads/5_11_05_Listing_1.txt
and after that you just call it whit something like:
use db_name
execute sp_ListObjects ‘P’
What do you think about this..?
Greatings, k
to list out all the month in a year in Sql Server
Hi ,
Is there any SQLquery to find out how many tables are created today?
Thanks in advance.
thanks great post
By MK Gandhi
to add srno in retrieved records using querry
do this for sql server 2000 for same result :
select *
from information_schema.routines where Routine_Type=’procedure’
AND DATEDIFF(D,last_altered, GETDATE()) <7
select @@databasename
if you want to find modified sp in the specific database
add the below conditionL
and specific_Catalog=’yourrdatabasename’
[...] SQL SERVER – 2005 – List All Stored Procedure Modified in Last N Days [...]
Thank u very much
the above information is very helpful. but
I want to list table name also????
Please help me
Hi Ramya,
To get tables, modified in last 7 days:
SELECT name
FROM sys.objects
WHERE type = ‘U’
AND DATEDIFF(D,modify_date, GETDATE()) < 7
Thanks,
Tejas
You are one SQL God!
You have helped many people more than any body in the world.
Hope you keep on doing great!!!
Thanks for the query, but as an auditor I need to know who made the modification, in other words,
I need know the:
what was modified (object name),
when (when that object was modified)
and the
who (who made the changes).
Is this possible?
Regards
Julio Valencia
Hello is there any way to find when the last reindexing was done on the database in sql server 2005?
I need the query about find modified procedures in sql 2000
Thanks dude! Exactly what I was looking for. Saved me hacking this out myself :-)
Hi,
I have run the below procedure in sql 2000 but i am getting the same date in both created and last_alterd column.But user is saying he has modified the Procedure 2 days back.
select *
from information_schema.routines where Routine_Type=’procedure’
AND DATEDIFF(D,last_altered, GETDATE()) <7
select @@databasename
if you want to find modified sp in the specific database
add the below conditionL
and specific_Catalog=’yourrdatabasename’
Kindly help for sql 2000.
hi pinal
i am new to sql server, and needs to tune one SP.
is there any way to find when any specific database last reindexed?
Hi,
this is bangaram, i am new to sql server i have some doubts
1.i have created 1 table and i have to update 1 attribute in that table how.
2.in 1 table first attribute is sl.no it has to be generated number automatically , How can i do this
Please reply fast
My stored procedure was modified by 3rd person,without my knowledge,is it possible? how can i avoid this?
Hi Muthu,
You can implement Database Trigger to restrict or log changes.
You will get many blogs to implement that
Thanks,
Tejas
SQLYoga.com
thx u very much, u really help me