Pair of atributes as a relation key - relational algebra

316 Views Asked by At

I'm trying to detect if the attribute pair (A, B) is the relation key for R(A, B, C). Specifically, I want to write a query in relational algebra that will return an empty set if and only if (A, B) is a relation key. Is it possible to somehow count the occurrence of pairs (A, B) and pick only those which occur more than once?

1

There are 1 best solutions below

0
AntC On

The key or keys for a relation is defined by the schema definition: (PRIMARY) KEY declaration or UNIQUE constraint.

a query in relational algebra that will return an empty set if and only if (A, B) is a relation key.

It is not possible to tell from the data alone what attribute(s) might be a key or keys. The best you can find from the data content is that some attribute or combination of attributes is not a key -- because there are rows that contain duplicates for that subset of attributes.