Site sponsored by: Idera The gold standard of SQL Server performance monitoring & diagnostics.
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share your SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

System Data Collection Reports
Recover Data Using Database Snapshots
Analyze and Fix Index Fragmentation in SQL Server 2008
Powerful Geographical Visualisations made easy with SQL 2008 Spatial (Part 2) ...

More     
 
Latest FAQ's

How to alter a User Defined Data Type?
How to unzip a File in SSIS?
How to view previous query plans?
ALTER TABLE SWITCH statement failed because the object '%.*ls' is not ...

More     
   
Latest Software Reviews

Spotlight on ApexSQL Doc 2008
ApexSQL Enforce
Embarcadero Change Manager
SQL Server DBA Dashboard

More     

articles >> general dba >> Track SP Changes by Automatically Saving Your ...

Track SP Changes by Automatically Saving Your SQL Server SP Text

By : Randy Dyess
Jul 20, 2003

Page 3 / 3

Next, I simply created a simple stored procedure that I could schedule that would save the text of all current stored procedures in all the databases on the server. You could expand this include the text of views, defaults, constraints, etc., if you wanted to.

 

IF OBJECT_ID('spProcVersion') IS NOT NULL
DROP PROCEDURE spProcVersion
GO

CREATE PROCEDURE spProcVersion @strDBName NVARCHAR(50)
AS
SET NOCOUNT ON

--This will hold the dynamic string.
DECLARE @strSQL NVARCHAR(4000)

--Set the string
SET @strSQL = 'INSERT INTO master.dbo.tStoredProcs(strDatabase,strProcName,strText)
SELECT ''' + @strDBName + ''', so.name, sc.text
FROM ' + @strDBName + '.dbo.sysobjects so
INNER JOIN ' + @strDBName + '.dbo.syscomments sc
ON so.id = sc.id
WHERE so.type = ''p''' -Only stored procedures

--Execute the string
EXEC dbo.sp_executesql @strSQL
GO

 

Next, create a job and execute the above stored procedure in every database on the server.

 

EXEC dbo.sp_MSforeachdb @command1 = 'EXEC master.dbo.spProcVersion ''?'''

 

Let the job run on whatever schedule you want; create any jobs you may need to delete information over x number of days; adjust this method to use linked servers if you want; and basically adjust it to meet your needs to do what you feel is necessary to protect yourself against accidental loss of a stored procedure.

You can find out more about the undocumented stored procedure sp_MSforeachdb in my last book Transact-SQL Language Reference Guide.

 

Copyright 2003 by Randy Dyess, All Rights Reserved www.TransactSQL.Com


<< Prev Page         








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved