Skip to main content

Posts

Showing posts from February, 2018

How to keep history of SQL Server stored procedure revisions

28 down vote accepted While I am in full agreement that source control is the right way to do this, I also understand that not all environments are disciplined enough to rely on that alone (if at all), and that sometimes changes have to made directly to keep the app running, save a client, what have you. You can use a DDL trigger to keep all revisions in a table in a separate database (and of course back up that database frequently). Assuming you have a utility database: USE Utility ; GO CREATE TABLE dbo . ProcedureChanges ( EventDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP , EventType NVARCHAR ( 100 ), EventDDL NVARCHAR ( MAX ), DatabaseName NVARCHAR ( 255 ), SchemaName NVARCHAR ( 255 ), ObjectName NVARCHAR ( 255 ), HostName NVARCHAR ( 255 ), IPAddress VARCHAR ( 32 ), ProgramName NVARCHAR ( 255 ), LoginName NVARCHAR ( 255 ) ); Now in your database, first let's grab what we'll ca