Solved

How to delete all stored procedures and views in database with one click?

Posted on 2010-11-21
1
517 Views
Last Modified: 2012-05-10
Hello,

I need a script in SQL 2005 to delete a all stored procedures and views in one database with one click?

Thanks

Zaki
0
Comment
Question by:zaki100
1 Comment
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 34185599
To drop all stored Procedures
 
/* Drop all non-system stored procs */ 

DECLARE @name VARCHAR(128) 

DECLARE @SQL VARCHAR(254) 

 

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name]) 

 

WHILE @name is not null 

BEGIN 

    SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']' 

    EXEC (@SQL) 

    PRINT 'Dropped Procedure: ' + @name 

    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 AND [name] > @name ORDER BY [name]) 

END 

GO

Open in new window


To drop all views
 
/* Drop all views */ 

DECLARE @name VARCHAR(128) 

DECLARE @SQL VARCHAR(254) 

 

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 ORDER BY [name]) 

 

WHILE @name IS NOT NULL 

BEGIN 

    SELECT @SQL = 'DROP VIEW [dbo].[' + RTRIM(@name) +']' 

    EXEC (@SQL) 

    PRINT 'Dropped View: ' + @name 

    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 AND [name] > @name ORDER BY [name]) 

END 

GO

Open in new window


http://stackoverflow.com/questions/536350/sql-server-2005-drop-all-the-tables-stored-procedures-triggers-constriants-an

Hope this helps
Raj
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now