Ask the Expert

Executing a trigger before SQL Server table is updated

Can I execute a trigger before an insert is created to a table. I need to create logging on the CRM system, but I do not have access to modify the CRM. Can I grab incoming values from the table and based on the ID, read and extract with a trigger before the table is updated?

    Requires Free Membership to View

You can, by creating an INSTEAD OF TRIGGER. However, I suspect you're really asking about an UPDATE trigger (by your description). Even AFTER triggers (ie the default type) allow you access to both the before and after versions of the data via the deleted and inserted virtual tables.

Check out this helpful tip:   
  • Optimize database triggers in SQL Server 2000
    It's hard to follow the logic behind triggers and easy to forget about them in time. Why and when should you use them? Learn about performance issues and design considerations.
  • This was first published in September 2007

    There are Comments. Add yours.

    TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

    REGISTER or login:

    Forgot Password?
    By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
    Sort by: OldestNewest

    Forgot Password?

    No problem! Submit your e-mail address below. We'll send you an email containing your password.

    Your password has been sent to: