Search code examples
databaseforeign-keysrelational-databasedatabase-normalizationthird-normal-form

Update problems with 1nf database tables


I have two database tables:
report(id, description) (key: id) and
registration(a, b, id_report) (key: (a, b));

id_report is a foreign key that references report id.
In the table registration there is the functional dependency a -> id_report.

So the table registration is 1nf but not 2nf.

Despite this i can not find insert/update/delete problems in the table registration. Is it possible?

Thanks


Solution

  • YOu said in a comment that you couldn't "find how problems could occur." (Emphasis added.) Here's how.

    Let's say your table "registration" starts off with data like this.

    a  b    id_report
    --
    1  10   13
    1  11   13
    1  12   13 
    2  27   14
    2  33   14
    

    The functional dependency a->id_report still holds. When we know the value for "a", we find one and only one value for "id_report".

    But the dbms can't directly enforce that dependency. That means the dbms will permit this update statement to run without error.

    update registration
    set id_report = 15
    where a = 1 and b = 10;
    
    a  b    id_report
    --
    1  10   15
    1  11   13
    1  12   13 
    2  27   14
    2  33   14
    

    Now your data is broken. When we know the value for "a", we now find two values for "id_report". In the earlier table, knowing that "a" equaled 1 meant we knew that "id_report" equaled 13. We no longer know that; if "a" equals 1, id_report might be either 13 or 15.