connectseekers.com

Tuesday, 29 December 2015

SQL Query To Drop or Delete All Table, View, Stored Procedure and Trigger

12/29/2015 - By Pranav Singh 0

In this article I will show you how you can drop the entire tables, views, stored procedure and triggers in sql server using a single query.



In this article first I will show you how you can drop or delete all tables, views, stored procedure and triggers from your sql server database.

Drip All SQL Tables:

EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"


Drop All SQL View:

DECLARE @view_name varchar(100)
DECLARE sqlview_cursor CURSOR
    FOR select table_name from INFORMATION_SCHEMA.views
OPEN sqlview_cursor
FETCH NEXT FROM sqlview_cursor INTO @view_name;
WHILE @@FETCH_STATUS = 0
BEGIN
  declare @sql varchar(100)
  set @sql='DROP VIEW '+@view_name ;
  exec(@sql);
  FETCH NEXT FROM sqlview_cursor INTO @view_name;
END
CLOSE sqlview_cursor;
DEALLOCATE sqlview_cursor;


Drop all SQL Triggers:

DECLARE @trigger_name varchar(100)
DECLARE sqltrigger_cursor CURSOR
    FOR select objectproperty(object_id('TriggerName'), 'ExecIsTriggerDisabled')
OPEN sqltrigger_cursor
FETCH NEXT FROM sqltrigger_cursor INTO @trigger_name;
WHILE @@FETCH_STATUS = 0
BEGIN
  declare @sql varchar(100)
  set @sql='DROP VIEW '+@trigger_name ;
  exec(@sql);
  FETCH NEXT FROM sqltrigger_cursor INTO @trigger_name;
END
CLOSE sqltrigger_cursor;
DEALLOCATE sqltrigger_cursor;



I think this will help you. Please let me know your comments.

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top