Domanda

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

È stato utile?

Soluzione

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.

Altri suggerimenti

A table can be denormalized and still not have any existing referential integrity issues.

The reason to normalize is to make it more difficult or impossible to create insert, update and delete anomalies. It is possible, but pretty hard, to manage all of the redundant data such that it remains consistent.

It's still a better idea to use a database in 3NF (or higher, if applicable) so that you aren't relying on programmers and users to keep you out of trouble. Sooner or later mistakes will happen.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top