Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:06:31+00:00 2026-06-04T10:06:31+00:00

For a simple sql-server update trigger, I may write a class like this: [Microsoft.SqlServer.Server.SqlTrigger

  • 0

For a simple sql-server update trigger, I may write a class like this:

[Microsoft.SqlServer.Server.SqlTrigger (Name="MyTrigger", Target="[dbo].[MyTable]", Event="FOR UPDATE")]
public static void MyTrigger() { //... my code }

But if I only want to trigger on one column update, that would that behave like :

create trigger myTrigger
on myTable
for update as
if update(MyColumn)
begin
    -- my code
end

what kind of Microsoft.SqlServer.Server.SqlTrigger attribute should I use ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:06:33+00:00Added an answer on June 4, 2026 at 10:06 am

    May be this could help you.

    [Microsoft.SqlServer.Server.SqlTrigger (Name="Trigger1", Target="Table1", Event="FOR UPDATE")]
    public static void Trigger1()
    {
        SqlConnection conn = new SqlConnection("context connection=true;");
        SqlCommand cmd = new SqlCommand("select top 0 * from Table1", conn);
    
        conn.Open();
    
        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
    
        if (SqlContext.TriggerContext.IsUpdatedColumn(dr.GetOrdinal("columnname")))
        {
            SqlContext.Pipe.Send("columnname was updated");
        }
        else
        {
            SqlContext.Pipe.Send("columnname was not updated");
        }
    
        dr.Close();
        conn.Close();
    } 
    

    You cannot prevent running the trigger selectively, it will always run no matter the columns updated. However, once launched you can consult the COLUMNS_UPDATED() function:

    Returns a varbinary bit pattern that indicates the columns in a table
    or view that were inserted or updated. COLUMNS_UPDATED is used
    anywhere inside the body of a Transact-SQL INSERT or UPDATE trigger to
    test whether the trigger should execute certain actions.

    So you would adjust your trigger logic to have appropiate action according to what columns where updated.

    That being said, calling WCF from SQLCLR is a very very bad idea. Calling WCF from a trigger is even worse. Your server will die in production as transactions will block/abort waiting on some HTTP response to crawl back across the wire. Not to mention that your calls are inherently incorrect in presence of rollbacks, as you cannot undo an HTTP call. The proper way to do such actions is to decouple the operation and the WCF call by means of a queue. You can do this with tables used as queues, you could use true queues or you could use Change Tracking. Any of these would allow you to decouple the change and the WCF call and would allow you to make the call from a separate process, not from SQLCLR

    Source: CLR Trigger only particular column get updated

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does this quite simple xquery takes 10min to execute in sql server (the
I have a fairly simple class that I want to save to SQL Server
I'm trying to create a simple trigger using TSQL (or SQL Server 2008). The
This is with Microsoft SQL Server 2008. I've got 2 tables, Employee and EmployeeResult
I have a data model like this in SQL Server: table Note - varchar
I have this very simple query in my database in SQL Server 2008 R2:
i m having following type of simple sql server table Here I want to
I am having an issue with the most simple command in SQL Server Management.
I use SQL Server 2005. I have a simple logging table that my web
I have a simple temp-table defined in SQL Server 2008 R2 representing a parent-child

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.