Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. SQL Server trigger code

SQL Server trigger code

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasesql-serversysadmin
5 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bernard Laplace
    wrote on last edited by
    #1

    DECLARE p_cursor CURSOR FOR
    SELECT TOP 1 SortDateStart AS DateStart, SortDateEnd AS DateEnd
    ...

    This code was in a trigger... :omg:

    T 1 Reply Last reply
    0
    • B Bernard Laplace

      DECLARE p_cursor CURSOR FOR
      SELECT TOP 1 SortDateStart AS DateStart, SortDateEnd AS DateEnd
      ...

      This code was in a trigger... :omg:

      T Offline
      T Offline
      Thomas Weller 0
      wrote on last edited by
      #2

      What especially are you considering to be a horror? 1. Using a database trigger at all (this is IMHO the true horror here :sigh: ) ? 2. Using TOP 1 without being explicit about it ? Regards Thomas

      _Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

      Programmer - an organism that turns coffee into software._

      B T 2 Replies Last reply
      0
      • T Thomas Weller 0

        What especially are you considering to be a horror? 1. Using a database trigger at all (this is IMHO the true horror here :sigh: ) ? 2. Using TOP 1 without being explicit about it ? Regards Thomas

        _Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

        Programmer - an organism that turns coffee into software._

        B Offline
        B Offline
        Bernard Laplace
        wrote on last edited by
        #3

        Well, I am ok with triggers so far you make a sensible use of them (which is not the case for the database where I found this). You should avoid the use of cursors with SQL Server, that is not good but most people would not call that an horror. The point is: Why on earth would someone open a cursor on a 1 row set???? In this case it is far more simple and efficient to type: SELECT TOP 1 @A=Column1, @B=Column2.... instead of declaring a cursor, fetch the data and close it.

        P 1 Reply Last reply
        0
        • T Thomas Weller 0

          What especially are you considering to be a horror? 1. Using a database trigger at all (this is IMHO the true horror here :sigh: ) ? 2. Using TOP 1 without being explicit about it ? Regards Thomas

          _Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

          Programmer - an organism that turns coffee into software._

          T Offline
          T Offline
          Thomas Weller 0
          wrote on last edited by
          #4

          Ah, now I get it... Sorry, I'm not very familiar reading such things. So I missed the point... :doh: Regards Thomas

          _Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

          Programmer - an organism that turns coffee into software._

          1 Reply Last reply
          0
          • B Bernard Laplace

            Well, I am ok with triggers so far you make a sensible use of them (which is not the case for the database where I found this). You should avoid the use of cursors with SQL Server, that is not good but most people would not call that an horror. The point is: Why on earth would someone open a cursor on a 1 row set???? In this case it is far more simple and efficient to type: SELECT TOP 1 @A=Column1, @B=Column2.... instead of declaring a cursor, fetch the data and close it.

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            Arnaud Lhopiteau wrote:

            The point is: Why on earth would someone open a cursor on a 1 row set?

            Not sure. Perhaps it was a rush job at the end of a Friday afternoon and they forgot what they were supposed to be doing?

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups