Q

Executing a trigger before SQL Server table is updated

Triggers in SQL Server can be executed before a table is updated. Get triggers to read and extract table values before and after the 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?
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

    Dig deeper on SQL-Transact SQL (T-SQL)

    Pro+

    Features

    Enjoy the benefits of Pro+ membership, learn more and join.

    Have a question for an expert?

    Please add a title for your question

    Get answers from a TechTarget expert on whatever's puzzling you.

    You will be able to add details on the next page.

    0 comments

    Oldest 

    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:

    -ADS BY GOOGLE

    SearchBusinessAnalytics

    SearchDataCenter

    SearchDataManagement

    SearchAWS

    SearchOracle

    SearchContentManagement

    SearchWindowsServer

    Close