Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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 (
  id SERIAL PRIMARY KEY,
  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.

—Theory


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://516072]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (13)
As of 2014-11-25 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (158 votes), past polls