Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^7: (OT) Why SQL Sucks (with a little Perl to fix it)

by Theory (Beadle)
on Dec 12, 2005 at 17:44 UTC ( #516072=note: print w/replies, xml ) Need Help??

in reply to Re^6: (OT) Why SQL Sucks (with a little Perl to fix it)
in thread (OT) Why SQL Sucks (with a little Perl to fix it)

If the table is is 3NF, then that unique constraint across all keys holds.

I don't think that's quite true. Consider this simple example:

CREATE TABLE supplier (
  name TEXT

INSERT INTO supplier (name) VALUES ('Apple');     -- Computer
INSERT INTO supplier (name) VALUES ('Microsoft');
INSERT INTO supplier (name) VALUES ('Apple');     -- Records

SELECT * FROM supplier;
 id |   name    
  1 | Apple
  2 | Microsoft
  3 | Apple

This table is in the third normal form, in so far as I understand it, because "none of the non-primary key attributes is a fact about any other non-primary key attribute". However, you'll notice that there is a duplicate, in that "Apple" is listed twice. That's because there are two different companies named "Apple". So this table is technically in 3NF, but you cannot have a unique index across all of its columns.

That's not to say that this is a good example, or that you couldn't work around this issue in various ways, but it demonstrates, I hope, that 3NF does not mandate that all columns be unique.


  • Comment on Re^7: (OT) Why SQL Sucks (with a little Perl to fix it)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://516072]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2018-01-23 11:01 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (243 votes). Check out past polls.