Find Created and Modified Stored Procedure in SQL

watch_later 5/15/2023

In this article, I am going to show you how you can get a list of all the created and modified stored procedures with their date and times. also, show you how you can get all the stored procedures from sys. objects

In an SQL server sysobjects Table contains one row for each object created within a database and it has a row for every constraint in SQL servers such as rules, logs, stored procedures and etc in SQL server database, So sys. projects table is used to fetch all the info about the database.

Find Created and Modified Stored Procedure
Find Created and Modified Stored Procedure

In my previous articles, I explained how to create and pass output parameters in stored procedures as well as how to execute a stored procedure in an SQL server and also explained how to perform the stored procedure from another stored procedure and how you can split comma delimited string in SQL server. in this article, I m gonna show you how to find the names of procedures created or modified from sys. objects table in SQL server.

Implementation

So, Lets we write an SQL script to get a list of all the stored procedure which is created or modified in the current month.

SQL Script

SELECT  name AS ProcedureName ,
        CONVERT(VARCHAR(10), SysObj.modify_date, 103) AS [Create/Modify Date] ,
        CONVERT(VARCHAR(15), CAST(SysObj.modify_date AS TIME), 100) [Create/Modify Time]
FROM    sys.objects SysObj
WHERE   SysObj.type = 'P'
        AND DATEDIFF(D, SysObj.modify_date, GETDATE()) < YEAR(GETDATE())

Here, the date condition in the above SQL script can be adjusted to retrieve required data based on need. i.g. If you want to get all the names of the procedure which been created or modified in the last 90 days,  then you just need to change your date condition shown below.

SELECT  name AS Procedure Name ,
        CONVERT(VARCHAR(10), SysObj.modify_date, 103) AS [Create/Modify Date] ,
        CONVERT(VARCHAR(15), CAST(SysObj.modify_date AS TIME), 100) [Create/Modify Time]
FROM    sys.objects SysObj
WHERE   SysObj.type = 'P'
        AND DATEDIFF(D, SysObj.modify_date, GETDATE()) < 90
OR
SELECT  name AS ProcedureName ,
        CONVERT(VARCHAR(10), SysObj.modify_date, 103) AS [Create/Modify Date] ,
        CONVERT(VARCHAR(15), CAST(SysObj.modify_date AS TIME), 100) [Create/Modify Time]
FROM    sys.objects SysObj
WHERE   SysObj.type = 'P'
ORDER BY SysObj.modify_date DESC

This SQL Script will return all the names of procedures of your database date wise latest created or modified.

Explanation

If You analyzed the above SQL script, all the info is fetched from the sys.objects table where sys.objects are used to fetch all the info from the database. 

We used type and date as a where condition to provide the name of all the stored procedures which were created based on entered date i.g. last 90 days, Last Month and etc, and type indicates Object Types in sys.objects there where P is a code of Object type and that can be described as SQL Stored Procedure.

Output

Sql Server Find Created and Modified Stored Procedure
SQL Server Find Created and Modified Stored Procedure

Summary

This article explains how to get a list of all the stored procedure which is created or modified in the SQL server.

Codingvila provides articles and blogs on web and software development for beginners as well as free Academic projects for final year students in Asp.Net, MVC, C#, Vb.Net, SQL Server, Angular Js, Android, PHP, Java, Python, Desktop Software Application and etc.

Thank you for your valuable time, to read this article, If you like this article, please share this article and post your valuable comments.

Once, you post your comment, we will review your posted comment and publish it. It may take a time around 24 business working hours.

Sometimes I not able to give detailed level explanation for your questions or comments, if you want detailed explanation, your can mansion your contact email id along with your question or you can do select given checkbox "Notify me" the time of write comment. So we can drop mail to you.

If you have any questions regarding this article/blog you can contact us on info.codingvila@gmail.com

sentiment_satisfied Emoticon