How to get a list of recently added stored procs from SQL Server database
Is it possible to get a list of stored procs from a SQL Server database where created/last updated date > yesterday?
sys.sql_modules
does not seem to have a date开发者_如何学Python. It must be stored somewhere else.
This will list all of the stored procedures along with their creation and modified dates:
SELECT name, modify_date
FROM sys.objects
WHERE type = 'P'
AND modify_date >= DATEADD(Day, -1, CONVERT(Date, GETDATE()))
ORDER BY modify_date DESC;
EDIT: Since modify_date
will always be equal to or after create_date
... Also note that you could just use sys.procedures
as another answer mentioned.
Information_Schema
has several views to help review various objects. Routines
is one of them
select *
from INFORMATION_SCHEMA.ROUTINES
Where CREATED > DATEADD(dd, DATEDIFF(dd, 0, getdate()-1), 0)
Order by CREATED Desc
The last two columns are for Created and Last_Modified.
sys.procedures
contains create_date
and modify_date
Use sys.procedures
. More direct than sys.objects
(you don't need to filter on type) and - while less portable than INFORMATION_SCHEMA
- the sys.
catalog views continue to be maintained and extended with information on new features, while INFORMATION_SCHEMA
is not.
For example, to find all the stored procedures created or modified since yesterday at midnight:
DECLARE @yesterday DATE = DATEADD(DAY, -1, CURRENT_TIMESTAMP);
SELECT OBJECT_SCHEMA_NAME([object_id]), name, create_date, modify_date
FROM sys.procedures
WHERE modify_date >= @yesterday
ORDER BY modify_date DESC;
Try this:
SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'P'
AND modify_date >= DATEADD(day, -1, getdate())
ORDER BY modify_date desc
精彩评论