Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Showing posts with label Cursor. Show all posts
Showing posts with label Cursor. Show all posts

Friday, 6 February 2015

Introduction

In this article i will explain how to delete all the views from Sql server database.
We can delete all views by executing single query. We don’t need to execute different query for each View.
Note: This command will delete all the views from your database.

Introduction

 In this article i will explain how to delete all the triggers from Sql Server database. If we want to delete all triggers from our database, then we can done it by using single query.


Note: This command will delete all the triggers from your database so use this command with care.

Implementation: In Sql server execute the following command:

Declare @trgName varchar(500)
Declare cur Cursor For Select [name] From sys.objects where type = 'tr'
Open cur
Fetch Next From cur Into @trgName
While @@fetch_status = 0
Begin
 Exec('drop trigger ' + @trgName)
 Fetch Next From cur Into @trgName
End
Close cur

Deallocate cur