Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #154

Re: SSE 2008: Trigger: Modifying Data to be Written

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!2a01:348:65::2.MISMATCH!news-transit.tcx.org.uk!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Erland Sommarskog <esquel@sommarskog.se>
Newsgroups comp.databases.ms-sqlserver, microsoft.public.sqlserver.programming
Subject Re: SSE 2008: Trigger: Modifying Data to be Written
Date Sat, 09 Apr 2011 11:22:07 +0200
Organization Erland Sommarskog
Lines 24
Message-ID <Xns9EC273A5FD7A3Yazorman@127.0.0.1> (permalink)
References <ab1vp6pks4qspe0bomof4pcnibgbpu8g10@4ax.com> <ino33e$1rk$1@dont-email.me> <p16vp6545phoh2i1ag0s2apt53guue997h@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 8bit
Injection-Info mx03.eternal-september.org; posting-host="DD6dU+BfJNjsjSP4/K/V7w"; logging-data="908"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eDM/HNoL52EGz1vujwK9f"
User-Agent Xnews/2006.08.24 Mime-proxy/2.1.c.0 (Win32)
Cancel-Lock sha1:yB0odWW/7wGXa0dzoNmowLKtbkE=
Xref x330-a1.tempe.blueboxinc.net comp.databases.ms-sqlserver:154

Cross-posted to 2 groups.

Show key headers only | View raw


Gene Wirchenko (genew@ocis.net) writes:
>      Thank you. I found an example of INSTEAD OF myself shortly after
> posting.  Half the battle of learning SQL Server is knowing exactly
> what to ask for, and sometimes, it is the tougher half!
 
I like to add that many developers would prefer to do this with an AFTER 
trigger. This means a higher overhead, because the bad data is first 
written to the table, and then you need to update the target table.
On the other hand, INSTEAD OF triggers gives you a maintainability 
problem. Since you need to redo the original statement, you need to
update the trigger every time you add a column to the table. If you 
forget you may get some headache sorting out what is going on.

What you really want is a BEFORE trigger where you can modify inserted.
But unfortunately SQL Server does not have BEFORE triggers.


-- 
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

SSE 2008: Trigger: Modifying Data to be Written Gene Wirchenko <genew@ocis.net> - 2011-04-08 15:11 -0700
  Re: SSE 2008: Trigger: Modifying Data to be Written "Bob Barrows" <reb01501@NOSPAMyahoo.com> - 2011-04-08 18:44 -0400
    Re: SSE 2008: Trigger: Modifying Data to be Written Gene Wirchenko <genew@ocis.net> - 2011-04-08 16:23 -0700
      Re: SSE 2008: Trigger: Modifying Data to be Written Erland Sommarskog <esquel@sommarskog.se> - 2011-04-09 11:22 +0200
        Re: SSE 2008: Trigger: Modifying Data to be Written Gene Wirchenko <genew@ocis.net> - 2011-04-09 21:29 -0700
          Re: SSE 2008: Trigger: Modifying Data to be Written Erland Sommarskog <esquel@sommarskog.se> - 2011-04-10 14:48 +0200
            Re: SSE 2008: Trigger: Modifying Data to be Written Gene Wirchenko <genew@ocis.net> - 2011-04-11 09:46 -0700
          Re: SSE 2008: Trigger: Modifying Data to be Written "Bob Barrows" <reb01501@NOSPAMyahoo.com> - 2011-04-10 08:54 -0400
            Re: SSE 2008: Trigger: Modifying Data to be Written Erland Sommarskog <esquel@sommarskog.se> - 2011-04-10 21:33 +0200
            Re: SSE 2008: Trigger: Modifying Data to be Written Gene Wirchenko <genew@ocis.net> - 2011-04-11 09:42 -0700
              Re: SSE 2008: Trigger: Modifying Data to be Written "Bob Barrows" <reb01501@NOyahooSPAM.com> - 2011-04-11 14:55 -0400
                Re: SSE 2008: Trigger: Modifying Data to be Written Gene Wirchenko <genew@ocis.net> - 2011-04-11 14:53 -0700
                Re: SSE 2008: Trigger: Modifying Data to be Written "Bob Barrows" <reb01501@NOSPAMyahoo.com> - 2011-04-11 18:49 -0400

csiph-web