liveBook · Manning

Key

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

A database key is a column or combination of columns used to identify rows or establish relationships between tables.

A key is a column or combination of columns that identifies rows or connects tables. Choose a value that is unique for the entity; then separate related data instead of repeating it. section 4.1.1

Use the two basic key types for different jobs:

  • Primary key: uniquely identifies a row in its table. section 4.1.1
  • Foreign key: points from a secondary table to a primary-key value or unique constraint, enforcing referential integrity. section 4.1.1
  • Avoid repeating shared details: move office information into Offices, identify each office with OfficeID, and reference it from Employees. section 4.1.1

Sales orders and products

A unique Sales Order Number can identify an order. Because one order can contain several products, store order items separately and reference the Products entity rather than duplicating product details. section 4.1.1

Figure 4.1 ERD for Sales Orders

Use the sales-order ERD to inspect how keys connect orders with their related entities. section 4.1.1

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

How deep it goes
Defines primary and foreign keys and works through entity splitting, but does not provide implementation syntax.
Examples
Uses Sales Order Number, OfficeID, Employees, Offices, products, and sales-order items as concrete schema examples.
What you can do after
Apply it to choose identifiers, split related entities, and reference shared records without duplicating their details.
How it connects
Connects primary keys, foreign keys, unique constraints, entities, one-to-many relationships, and referential integrity.

Also explained in

Compare how 10 books explain key →

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.