Sql Server: Get Created or Modified Date of Tables, Stored Procedures, Views and Functions

Introduction:  In this article I am going to share how to know when a table, stored procedure, views or user defined function (scalar or table valued) was created or last updated by passing the database object name or we can also get all the above specified database objects created/updated between specified dates.

In previous articles i explained How to Find all foreign keys referring to particular table

Get Created or Modified Date of Tables, Stored Procedures, Views and Functions In Sql server

Implementation: Let’s write the query to get the desired results.

Get created and last modified date by database object name

Suppose we want to get the created and last modified date of any database objects e.g. "tbEmployee" table the query will be as:

DECLARE @StartDate DATE='2015-05-20', @EndDate DATE='2017-01-10'

SELECT SC.Name AS SchemaName, OB.Name as ObjectName,type_desc AS ObjectType , [type], create_date AS CreatedOn
FROM sys.objects OB
INNER JOIN sys.schemas SC ON OB.Schema_Id=Sc.Schema_Id
WHERE OB.Name=tbEmployee' AND [Type] IN('U','P', 'V', 'FN','TF')

U: User Table
P: Stored Procedure
V: View
FN: User defined Scalar Function
TF: User Defined Table Values Function

Result will be as:
Schema
ObjectName
ObjectType
type
CreatedOn
LastModifiedOn
dbo
tbEmployee
USER_TABLE
U
2016-09-06 23:11:25.657
2016-10-07 23:20:51.550

Get all database objects created and last modified between specified dates

DECLARE @StartDate DATE='2015-05-20', @EndDate DATE='2017-01-10'

SELECT SC.Name AS SchemaName, OB.Name as ObjectName,type_desc AS ObjectType , [type], create_date AS CreatedOn
FROM sys.objects OB
INNER JOIN sys.schemas SC ON OB.Schema_Id=Sc.Schema_Id
WHERE create_date BETWEEN @StartDate AND @EndDate AND [Type] IN('U','P', 'V', 'FN','TF')
ORDER BY create_date DESC


Result will be as shown in image above at the top.

 Now over to you:
A blog is nothing without reader's feedback and comments. So please provide your valuable feedback so that i can make this blog better and If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linkedin and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates. 
Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..