Created
March 27, 2019 16:57
-
-
Save allenbrooks55/7de9963b26dd27519f882e093e5a44e3 to your computer and use it in GitHub Desktop.
Drops all stored procedures in a given SQL Server database.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE Procedure [dbo].[DeleteAllProcedures] | |
| AS | |
| DECLARE @schemaName varchar(500) | |
| DECLARE @procName varchar(500) | |
| DECLARE cur cursor | |
| FOR SELECT s.Name, p.Name FROM sys.procedures p | |
| INNER JOIN sys.schemas s ON p.schema_id = s.schema_id | |
| WHERE p.type = 'P' AND is_ms_shipped = 0 AND p.name NOT LIKE 'sp[_]%diagram%' | |
| ORDER BY s.Name, p.Name | |
| OPEN cur | |
| FETCH NEXT FROM cur INTO @schemaName,@procName | |
| WHILE @@fetch_status = 0 | |
| BEGIN | |
| if @procName <> 'DeleteAllProcedures' | |
| exec('drop procedure ' + @schemaName + '.' + @procName) | |
| FETCH NEXT FROM cur INTO @schemaName,@procName | |
| END | |
| CLOSE cur | |
| DEALLOCATE cur |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment