Professional Web Applications Themes

Do triggers use *lazy* OR ? - Microsoft SQL / MS SQL Server

I don't believe it will execute the OR if the first expression is true. But you can test it easy enough by making the UDF error if called and run it. -- Andrew J. Kelly SQL Server MVP "Zig Mandel" <nonehotmail.com> wrote in message news:evkPGRBQDHA.2244TK2MSFTNGP11.phx.gbl... > I have a trigger that looks like this (simplified): > [assume a table T with a bit column 'fSelected'] > > trigger for table T: > CHECK(fSelected=0 OR UserFunction1()) > > in most cases, fSelected will be 0. Does that mean that the UserFunction1() > call will not be executed by the server? (this ...

  1. #1

    Default Re: Do triggers use *lazy* OR ?

    I don't believe it will execute the OR if the first expression is true. But
    you can test it easy enough by making the UDF error if called and run it.

    --

    Andrew J. Kelly
    SQL Server MVP


    "Zig Mandel" <nonehotmail.com> wrote in message
    news:evkPGRBQDHA.2244TK2MSFTNGP11.phx.gbl...
    > I have a trigger that looks like this (simplified):
    > [assume a table T with a bit column 'fSelected']
    >
    > trigger for table T:
    > CHECK(fSelected=0 OR UserFunction1())
    >
    > in most cases, fSelected will be 0. Does that mean that the
    UserFunction1()
    > call will not be executed by the server? (this is an expensive function,
    and
    > I only want it called when fSelected <> 0
    >
    > Thank you.
    >
    >
    >

    Andrew J. Kelly Guest

  2. #2

    Default Re: Do triggers use *lazy* OR ?

    It is most likely that the UDF will not be called if the 'simple'
    predicate is true. However, you cannot depend on this behavior. It is
    perfectly valid for SQL-Server to call UserFunction1 (or even call is
    several times).

    Gert-Jan


    Zig Mandel wrote:
    >
    > I have a trigger that looks like this (simplified):
    > [assume a table T with a bit column 'fSelected']
    >
    > trigger for table T:
    > CHECK(fSelected=0 OR UserFunction1())
    >
    > in most cases, fSelected will be 0. Does that mean that the UserFunction1()
    > call will not be executed by the server? (this is an expensive function, and
    > I only want it called when fSelected <> 0
    >
    > Thank you.
    Gert-Jan Strik Guest

  3. #3

    Default Re: Do triggers use *lazy* OR ?

    Zig,

    You may be able to force the order of evaluation with

    check (
    case when fSelected = 0 then 1
    when dbo.UserFunction1(parameters?) = desiredresult? then 1
    else 0 end
    = 1
    )

    Steve Kass
    Drew University

    Zig Mandel wrote:
    >I have a trigger that looks like this (simplified):
    >[assume a table T with a bit column 'fSelected']
    >
    >trigger for table T:
    >CHECK(fSelected=0 OR UserFunction1())
    >
    >in most cases, fSelected will be 0. Does that mean that the UserFunction1()
    >call will not be executed by the server? (this is an expensive function, and
    >I only want it called when fSelected <> 0
    >
    >Thank you.
    >
    >
    >
    >
    >
    Steve Kass Guest

Similar Threads

  1. Lazy Loading Objects
    By BillHeit in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: April 22nd, 11:10 PM
  2. SEGV when lazy loading!
    By Mr T in forum AIX
    Replies: 3
    Last Post: September 16th, 08:59 AM
  3. Stop Being Lazy!
    By Nikolai Weibull in forum Ruby
    Replies: 5
    Last Post: August 13th, 11:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139