-1

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?

philipxy
  • 14,867
  • 6
  • 39
  • 83
  • [Re relational querying.](https://stackoverflow.com/a/24425914/3404097) – philipxy Mar 15 '22 at 22:16
  • What do you mean,"the relation key"? There can be >1 CK & further superkeys & a PK is just a CK you pick. A superkey is a unique subtuple, a CK is a superkey containing no smaller superkey. You realize that a value for a base/variable/schema only tells you what FDs don't hold, not which do? PS A SQL PK constraint actually means UNIQUE NOT NULL & could contain a smaller UNIQUE. Plus CK & superkey don't have fixed meanings in SQL & UNIQUE & duplicate & DISTINCT have special meanings. [Does an empty SQL table have a superkey? Does every SQL table?](https://stackoverflow.com/a/46029100/3404097) – philipxy Mar 15 '22 at 23:54

1 Answers1

0

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.

AntC
  • 2,623
  • 1
  • 13
  • 20