DEV Community

Cover image for Finding Super Keys
hebaShakeel
hebaShakeel

Posted on

4 1

Finding Super Keys

How to find a Super Key in a Relation

Consider a relation R(a1, a2, a3,.....an), where n = number of attributes in a relation.
Suppose Candidate Key = (a1)
Find total SKs.

No. of Super Keys = 2^(n-1)

Example 1
R(ABCDE), CK={B}
Find total SKs

Here n = 5
n-1 = 4
Therefore total number of SKs = 2^4 = 16

Example 2
R(a1, a2, a3,....an), CK={a1a2}
Find total SKs

No. of Super Keys = 2^(n-2), since here there are 2 attributes in the candidate Key.

Example 3
R(XYZMN), CK={ZM}
Find total SKs

Here n = 5
No. of attributes in Candidate Key = 2
Therefore total number of SKs = 2^(5-2) = 2^3 = 8

Example 4
R(a1, a2, a3,....an), CK={a1,a2}
Find total SKs

All SKs which have either a1 or a2 or a1a2
n(a1 U a2) = n(a1) + n(a2) - n(a1a2)

Therfore No. of Super Keys = 2^(n-1) + 2^(n-1) - 2^(n-2)

Example 4
R(A,B,C,D,E,F), CK={A,DF}
Find total SKs

Total number of SKs = 2^(6-1) + 2^(6-2) - 2^(6-3) = 32+16-8 = 40

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay