Difference between super key and composite key

后端 未结 4 1585
清酒与你
清酒与你 2021-02-06 08:02

I need to understand the difference between super key and composite key. The examples I found made more confused. Can you please simply clarify what is the difference? Thanks

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-06 08:11

    Yes, I agree with @Branko, the accepted answer is not the accurate and not clear.

    I'll take example of an Employee table:

    CREATE TABLE Employee (
    Employee ID, 
    FullName, 
    SSN, 
    DeptID
    );
    

    And to know difference b/w Super & Candidate keys, let's check first what are other types of keys?

    1. Candidate Key: are individual columns in a table that qualifies for uniqueness of all the rows. Here in Employee table EmployeeID & SSN are Candidate keys.

    2. Primary Key: is the columns you choose to maintain uniqueness in a table. Here in Employee table you can choose either EmployeeID or SSN columns, EmployeeID is preferable choice, as SSN is a secure value.

    3. Alternate Key: Candidate column other the Primary column, like if EmployeeID is PK then SSN would be the Alternate key.

    4. Super Key: If you add any other column/attribute to a Primary Key then it become a super key, like EmployeeID + FullName is a Super Key.

    5. Composite Key: If a table don't have any individual columns that qualifies for a Candidate key, then you have to select 2 or more columns to make a row unique. Like if there is no EmployeeID or SSN columns, then you can make FullName + DateOfBirth as Composite primary Key. But still there can be a narrow chance of duplicate row.

    Reference

提交回复
热议问题