SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


CASCADE - 2


CASCADE - 2

Author
Message
kevin.l.williams
kevin.l.williams
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3415 Visits: 1323
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?



TomThomson
TomThomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14322 Visits: 12197
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.

Tom

Hugo Kornelis
Hugo Kornelis
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11020 Visits: 11994
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.

Of course, it is indeed bad practice to form values like this and store them as single column for real data. But for some sample code, I don't object to it.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Carla Wilson-484785
Carla Wilson-484785
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1917 Visits: 1950
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 easily visualize which rows belong together, but not with any other intention.

Of course, it is indeed bad practice to form values like this and store them as single column for real data. But for some sample code, I don't object to it.


+1 - It's just a simple loop to generate some sample data.
Dana Medley
Dana Medley
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2494 Visits: 1696
Ez Pz. No got'cha in this question. Thanks!



Everything is awesome!
kevin.l.williams
kevin.l.williams
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3415 Visits: 1323
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.



Revenant
Revenant
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7359 Visits: 4863
Thanks for an easy one, Ron!
kapil_kk
kapil_kk
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3091 Visits: 2766
good question for the day :-)

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
mickyT
mickyT
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1584 Visits: 3317
Thanks for the question
TomThomson
TomThomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14322 Visits: 12197
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

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search