Delete all triggers in the SQL Server database with a T-SQL

Source: Internet
Author: User

When data is extracted or synchronized using a trigger, the extraction software will create a trigger for each extracted database table. It is very cumbersome to manually delete all the triggers when there are many triggers, because a company's system often needs to delete triggers, so write a segment of T-SQL to automatically delete all triggers. The cursor, loop, and other knowledge points are used. You can also refer to them when writing related programs in the future.

Use Database Name godeclare @ tname varchar (100), @ cmd varchar (150) declare CSR cursor for select name from sysobjects where xtype = 'tr' open csrfetch next from CSR into @ tnamewhile @ fetch_status = 0 beginset @ cmd = 'drop trigger' + @ tname; exec (@ cmd) Fetch next from CSR into @ tnameenddeallocate csrgo

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.