Using Microsoft SQL Server triggers

Michelle Gutzait, Contributor

Intro | Part 1 | Part 2 | Part

    Requires Free Membership to View

3 | Part 4 | Part 5 | Part 6 | Part 7

One of my clients called me. The frantic communication went something like this:

Our applications started to do crazy things in the database," said the client. "We don't understand what is happening. New rows are added to one table and another table is changed. We successfully update a row, and when we refresh the application form, different data appears. Also, it takes too long to update a single row. Is it a virus? Can it be that SQL Server has a bug in it?

I examined their database. Almost every table had at least one trigger attached to it. I tried to follow the logic of only one update, and I was terrified. It took me hours to understand the logic of this "spaghetti" database. At least the "recursive triggers" option was disabled. Imagine what could happen if it wasn't? I would have lost several more hours.

This is the ultimate dilemma: Should you use triggers in SQL Server? What are the implications? Will database triggers affect SQL Server performance and by how much? In this tip, I pinpoint some considerations for using triggers in SQL Server.



Explore Microsoft SQL Server triggers

 Home Introduction
 Part 1 Why use triggers in SQL Server?
 Part 2 Designing and implementing triggers in SQL Server
 Part 3 Example: INSTEAD OF triggers vs. AFTER triggers
 Part 4 Example: One trigger vs. two for the same logic
 Part 5 Example: Nested triggers in SQL Server
 Part 6 Example: Heavy insertion process from OLTP and triggers
 Part 7 Example: Cursors in SQL Server triggers


This was first published in May 2006

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

    ABOUT THE AUTHOR:   
    Michelle Gutzait works as a team member of the SQL Server Database Experts at www.pythian.com, a worldwide company providing Remote Administration services for databases, operating systems, SANs and networks. Gutzait has been involved in IT for 20 years as a developer, business analyst and database consultant. For the past 10 years, she has worked exclusively with SQL Server. Her skills include SQL infrastructure and database design, performance tuning, security, high availability, disaster recovery, very large databases, replication, T-SQL coding, DTS/SSIS packages, administrative and infrastructure tools development, reporting services and more.