Auditing Stored Procedure Changes in a Regulated Environment

By Tom Nonmacher

In a highly regulated environment, it is crucial to keep track of all changes made to stored procedures. Auditing these changes can help in maintaining regulatory standards, diagnosing issues, and providing a clear trail of actions for accountability purposes. This post will discuss how to audit stored procedure changes in various SQL platforms including SQL Server 2012, SQL Server 2014, MySQL 5.6, DB2 10.5, and Azure SQL.

SQL Server 2012 and 2014 provide a feature known as DDL (Data Definition Language) Triggers which can be used to monitor and log changes to stored procedures. When a stored procedure is created, altered or dropped, the DDL trigger fires and records the details of the event. Here is a sample DDL trigger for auditing stored procedures:


CREATE TRIGGER Audit_Stored_Procedures
ON DATABASE
FOR CREATE_PROCEDURE, ALTER_PROCEDURE, DROP_PROCEDURE
AS
BEGIN
    INSERT INTO ProcedureAuditLog (EventDate, EventType, EventUser, ObjectName)
    VALUES (GETDATE(), EVENTDATA().value('(/EVENT_INSTANCE/EventType)[1]', 'nvarchar(100)'), 
    EVENTDATA().value('(/EVENT_INSTANCE/LoginName)[1]', 'nvarchar(100)'), 
    EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]', 'nvarchar(100)'))
END

MySQL 5.6 does not have built-in DDL triggers like SQL Server. However, you can use the general query log to record all changes made to stored procedures. To enable the general query log, you can set the 'general_log' global system variable to ON. However, be aware that the general query log can quickly grow in size and impact performance, so this should only be a temporary solution.

For DB2 10.5, you can use the ADMIN_GET_TAB_INFO function to retrieve information about when a stored procedure was last modified. However, this function does not keep a history of changes. To keep a history, consider creating a DDL trigger similar to the SQL Server example above.


SELECT CREATE_TIME, ALTER_TIME, VALID 
FROM SYSIBM.SYSROUTINES
WHERE ROUTINENAME = 'your_stored_procedure_name'

Azure SQL has built-in support for auditing, including changes to stored procedures. Azure SQL Auditing logs can be written to Azure Storage, Azure Log Analytics, and Azure Event Hubs. To enable auditing for stored procedures, you'll need to configure the database's auditing policy to include the 'SCHEMA_OBJECT_CHANGE_GROUP' action group.

In conclusion, while each platform has its own ways of auditing stored procedure changes, the principle remains the same. The key is to ensure that you have a system in place to track these changes, so you can maintain compliance, diagnose issues, and have a clear audit trail. The specific method will depend on the capabilities of your SQL platform and the specific requirements of your environment.

Check out the latest articles from all our sites:

Privacy Policy for sqlsupport.org

Last updated: May 06, 2026

sqlsupport.org respects your privacy and is committed to protecting any personal information you may provide while using this website.

This Privacy Policy document outlines the types of information that are collected and recorded by sqlsupport.org and how we use it.

Information We Collect

  • Internet Protocol (IP) addresses
  • Browser type and version
  • Pages visited
  • Time and date of visits
  • Referring URLs
  • Device type

Cookies and Web Beacons

sqlsupport.org uses cookies to store information about visitors preferences and to optimize the users experience.

How We Use Your Information

  • Operate and maintain our website
  • Improve user experience
  • Analyze traffic patterns
  • Prevent fraudulent activity

Contact

Email: admin@sqlsupport.org




44C936
Please enter the code from the image above in the box below.