liveBook · Manning

Superkey

As explained in 100 SQL Server Mistakes and How to Avoid Them

A super key is a set of attributes that uniquely identifies every row in a relation, whether or not it is minimal.

A superkey is a set of attributes that uniquely identifies every row in a relation. A candidate key is a minimal superkey: removing any attribute would stop it from uniquely identifying rows. section 4.1.3

When selecting keys during normalization, check whether one attribute is enough before building a composite key:

  • Sales Order Number uniquely identifies Sales records, so it can serve as a single-attribute candidate key. section 4.1.3
  • Purchase Order Number uniquely identifies Purchasing records and is a superkey by itself. section 4.1.3
  • Product Name alone fails when supplier parts share names with customer products; Product Name plus Product Type Name uniquely identifies a product. section 4.1.3

Avoid the product-name mistake

Do not assume a familiar label is unique. If products can share a name, use the additional attribute needed to distinguish records, then carry that attribute into related sales and purchasing data. section 4.1.3

    Sales
    Sales Order Date
PK  Sales Order Number
    Sales Person First Name
    Sales Person Last Name
    Sales Person Email
    Sales Area Name
    Sales Area Manager First Name
    Sales Area Manager Last Name
    Customer Company Name
    Customer Contact First Name
    Customer Contact Last Name
    Customer Contact Email
FK  Invoice Address Street
FK  Invoice Address Zip Code
FK  Delivery Address Street
FK  Delivery Address Zip Code
    Sales Order Delivery Due Date
    Sales Order Delivery Actual Date
    Currier Used for Delivery
    
      Sales Order Details
PK FK Product Name
PK FK Product Type Name
      Quantity
PK FK Sales Order Number
    
    Address
PK  Street
    Area
    City
PK  Zip Code
    
    Purchasing
    Supplier Name
    Supplier Contact First Name
    Supplier Contact Last Name
    Supplier Contact Email
FK  Supplier Address Street
FK  Supplier Address Zip Code
    Purchase Order Date
PK  Purchase Order Number
    
      Purchase Order Details
PK FK Product Name
PK FK Product Type Name
      Quantity
PK FK Purchase Order Number
    
    Products
PK  Product Name
    Product Stock Level
    Product Next Manufacture Date
    Product Next Manufacture Quantity
    Back Order Manufacturing ID
PK  Product Type Name
    Product Type Description
    Product Category Name
    Product Category Description
    Product Subcategory Name
    Product Subcategory Description

Inspect the normalized design to see composite primary and foreign keys for Sales Order Details, including Product Name and Product Type Name. section 4.1.3

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Defines superkeys and minimal candidate keys, then works through single-attribute and composite identification cases.
Examples
Uses Sales Order Number, Purchase Order Number, and a Product Name plus Product Type Name pair.
What it assumes
Introduces relations as table equivalents while applying key selection within first normal form.
What you can do after
Evaluate/understand whether one attribute or a combination uniquely identifies each relation row.
How it connects
Connects superkeys with first normal form, candidate keys, composite keys, prime attributes, and relations.

Also explained in

Compare how 2 books explain superkey →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.