CASCADE - 2

  • L' Eomot Inversé (3/26/2013)


    kevin.l.williams (3/26/2013)


    L' Eomot Inversé (3/26/2013)


    And intensly I dislike the horrible violation of 1NF - code examples like this risk teaching really awful habits to inexperienced people who see them.

    I'm very embarrassed to ask this but how does the code example violate 1NF?

    Look at the construction of the field OrderDetailID in insertion code. You'll see that the orderdetailID (a single column) is constructed as an integer which when written out in decimal notation has the detail number within the order for which it is being created in the LS three digits and the order number in the more significant digits. This violates the principle that a row contains a single atomic value in each column, never multiple values in a single column - because here we have an order number and an order detail detail number both in the same column in each row.

    Thanks for explaining, I didn't notice this about the data.

    It appears his example update on orderID points out why this is bad practice.

  • Thanks for an easy one, Ron!

  • good question for the day 🙂

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Thanks for the question

  • Hugo Kornelis (3/26/2013)


    I think you're reading a bit too much into the code used to create some sample data, Tom. I suspect ROn used this method to eaily visualize which rows belong together, but not with any other intention.

    Oh, I don't for a moment imagine that Ron was intentionally breaking 1NF, or that he even noticed he was doing. And of course it's completely irrelevant to the question - any old table will do as long as it has a foreign key. That's why I said it was a good question apart from the strange wording of the answer options.

    But I've often been hit by junionr developers seeing something and thinking "Oh, that's neat, perhaps I can use that" when the something they saw was absolutely terrible practice but acceptable in a particular context because it wasn't relevant there. So I try to avoid doing such things even when they are not relevant to thetask at hand, and believe that everyone should do so. Especially in contexts where they are likely to be seen by a lot of not particularly experienced people.

    Tom

  • EZ PZ today.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Good one Ron 🙂

    I think you have posted two questions on this topic earlier. If it is possible, then please post more questions on this topics with different kind of scenario. This will give us very good information. It will help us to get some more interesting scenario.

    🙂

    Thanks
    Vinay Kumar
    -----------------------------------------------------------------
    Keep Learning - Keep Growing !!!

  • Thanks for the Easy Points

  • L' Eomot Inversé (3/26/2013)


    Hugo Kornelis (3/26/2013)


    I think you're reading a bit too much into the code used to create some sample data, Tom. I suspect ROn used this method to eaily visualize which rows belong together, but not with any other intention.

    Oh, I don't for a moment imagine that Ron was intentionally breaking 1NF, or that he even noticed he was doing. And of course it's completely irrelevant to the question - any old table will do as long as it has a foreign key. That's why I said it was a good question apart from the strange wording of the answer options.

    But I've often been hit by junionr developers seeing something and thinking "Oh, that's neat, perhaps I can use that" when the something they saw was absolutely terrible practice but acceptable in a particular context because it wasn't relevant there. So I try to avoid doing such things even when they are not relevant to thetask at hand, and believe that everyone should do so. Especially in contexts where they are likely to be seen by a lot of not particularly experienced people.

    I agree in principle but can we expect everyone who writes a QotD to check their question for best practice in the coding? Might people be deterred from posing a QotD if they're worried about getting the coding practice picked to pieces? Having said that, was there any need for a mixture of @val1 and @val2 to be used in the setting of the first column. Would the question have achieved the same result if some arithmetic on just @val2 was used?

  • paul.knibbs (3/26/2013)


    This seemed so simple I went and ran the code, sure there must be a catch of some kind--turns out there wasn't, it was as simple as is seemed at first viewing. 🙂

    +1

    --
    Dineshbabu
    Desire to learn new things..

  • Nice question. I do not care about the wording, it worked for me.

    M.

    Not all gray hairs are Dinosaurs!

  • Another good question on cascade after the one on delete. 🙂

  • Great ! That cascading

Viewing 13 posts - 16 through 28 (of 28 total)

You must be logged in to reply to this topic. Login to reply