How to find who created a stored procedure in SQL Server

In the above section, we have discussed how to access various information in the log files of the SQL Server Instance. You can use the SQL Server Profiler to access the log information.

How to find who created a stored procedure in SQL Server

You can find the user who created the stored procedure using the Schema Changes History in the SQL Server Management Studio. You can find the name of the user in the LoginName column of the log files.

However, you can also execute the following T-SQL query to make your task simple:

SELECT ObjectName, LoginName , StartTime
FROM sys.fn_trace_gettable('C:\Program Files\Microsoft SQL Server\MSSQL15.SQLEXPRESS\MSSQL\Log\log_27.trc',default)
WHERE EventClass= 46 and ObjectName= 'ProcedureSales'
How to find who created a stored procedure in SQL Server
  • Replace the path of the log file and name of the stored procedure that you want to search for in the above query.
  • EventClass = 46 refers to the creation of object.
  • LoginName is the user who created the stored procedure.

Thus, you might have learned how you can find who created a particular stored procedure in SQL Server.

Read: SQL Server stored procedure return value

How to find owner of stored procedure in SQL Server

In this section, you will learn how you can find the owner of a stored procedure in SQL Server.

The sp_stored_procedures is a system-defined stored procedure that returns some basic information about the stored procedures. You can use this procedure to find the owner of a stored procedure. Executing it will give you the output like the below image.

EXEC sp_stored_procedures 
How to find owner of stored procedure in SQL Server

If you want to find the owner of a particular stored procedure, you can pass the name of the stored procedure as an input parameter. For example, if I want to know the owner of a stored procedure named Circle, I will write the query as:


EXEC sp_stored_procedures 'Circle
find owner of stored procedure in SQL Server

Thus, you might have learned how you can find the owner of a stored procedure in SQL Server.

Conclusion

This article discusses how to find who created a stored procedure in SQL Server, as explained in this article. You can choose the approach that best suits your requirements.

You may also like following the articles below.

Top 200 SQL Server Interview Questions and Answers

Free PDF On Top 200 SQL Server Interview Questions And Answers

Download A 40 pages PDF And Learn Now.