sqlt-sqlsql-update

TSQL, update col a = 0 set all the values for col a =0 in the table


I am trying to find way to do below in SQL table, where a is bit data type


Solution

  • You can use the INSTEAD OF trigger. It's a Highlander-type trigger, meaning there can only be one of it on a table (for every operation).

    CREATE TRIGGER MyTable_SetBitColumn ON MyTable INSTEAD OF UPDATE
    AS BEGIN
      UPDATE MyTable
      SET BitColumn = i.BitColumn
      FROM (SELECT TOP 1 * FROM inserted) i
    END