liveBook · Manning

Primary key

Also called PK

A primary key is a field or combination of fields whose values uniquely identify each row or item in a data store.

How 22 Manning books explain it

ScyllaDB in Action

A primary key is a table key that uniquely identifies rows and determines their key-based ordering.

How it is used
Guides table design by connecting row identity and partitioning to the queries an application must serve.
How deep it goes
Explains definition, schema syntax, partition-key position, clustering order, inserts, and denormalized table variants without detailing identifier-generation drawbacks.
Examples
Uses restaurant reviews keyed by restaurant, order time, and food, plus article and article-summary tables keyed by IDs and query fields.
What you can do after
Apply it via CQL by defining keys that uniquely identify rows and align partitions and ordering with intended reads.

Read how ScyllaDB in Action explains primary key →

Grokking Relational Database Design

A primary key constraint is an SQL constraint that requires primary-key values to be unique and non-NULL within a table.

How it is used
Identifies each table row and anchors relationships through foreign keys.
How deep it goes
Defines keys, compares candidate and superkeys, guides selection, and implements single-column, named, and composite constraints.
Examples
Uses product_id for products and reviews, user identifiers, email-based SQL definitions, and a purchase_id-plus-code composite key.
What you can do after
Build it from scratch by selecting candidate keys and declaring single-column or composite primary key constraints.

Read how Grokking Relational Database Design explains primary key →

Learn SQL in a Month of Lunches

A primary key constraint is a database rule requiring a table's primary-key values to uniquely identify rows and not be null.

How it is used
Establishes stable row identifiers for relating tables, creating joins, and reducing repeated descriptive data.
How deep it goes
Explains uniqueness, required values, immutability, referential integrity, composite keys, creation syntax, and duplicate-data repair.
Examples
Uses CategoryID and TitleID relationships, a category table, and duplicate OrderID–OrderItem rows in orderitem.
What you can do after
Operate/configure it by adding named single-column or composite PRIMARY KEY constraints and correcting duplicate key data first.

Read how Learn SQL in a Month of Lunches explains primary key →

DuckDB in Action

A primary key is a column or combination of columns whose values uniquely identify every row in a table.

How it is used
Defines row identity, protects data integrity, and supplies reliable join targets in a normalized DuckDB schema.
How deep it goes
Explains single, composite, natural, and surrogate choices with executable definitions, but defers broader migration mechanics.
Examples
Demonstrates systems, readings, and prices tables, plus duplicate inserts and conflict-aware updates.
What you can do after
Build it from scratch by defining appropriate keys and diagnose duplicate-key failures during inserts.

Read how DuckDB in Action explains primary key →

Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

A DynamoDB primary key is the attribute or combination of attributes that uniquely identifies an item in a table.

How it is used
Identifies DynamoDB items and shapes how an application retrieves users and groups tasks by user.
How deep it goes
Defines one- and two-attribute keys, then works through table creation and key-based reads; does not explore key changes after creation.
Examples
Uses AWS CLI user and task tables, Node.js item lookups, and a retried blog-post insert.
What you can do after
Build it from scratch by choosing a DynamoDB key schema, creating tables, and retrieving items by key.

Read how Amazon Web Services in Action, Third Edition: An in-depth guide to AWS explains primary key →

Functional Design and Architecture: Examples in Haskell

A primary key is a field or combination of fields that uniquely identifies a record in a database.

How it is used
Uses primary keys to identify records and prevent entity-key mismatches in persistence models.
How deep it goes
Works through composite-key design, tagged key types, and a beam Table instance; illustrates generic loading without detailing its implementation.
Examples
Uses meteor and comet keys, a meteor table’s composite natural key, and a beam integer ID.
What you can do after
Apply it via beam to declare a table key and use entity-specific key types in a key–value model.

Read how Functional Design and Architecture: Examples in Haskell explains primary key →

Build Python Web Apps with Streamlit

A primary key is a column or set of columns whose combined values uniquely identify each row in a data table.

How it is used
Identifies rows in sales data and relational tables for a dashboard and a CRUD app.
How deep it goes
Defines single-column and composite keys, then demonstrates SQL declarations and a foreign-key relationship.
Examples
Uses a seven-column sales key, unique usernames, and automatically supplied haiku IDs.
What you can do after
Apply it via PostgreSQL by declaring a primary key in a CREATE TABLE statement.

Read how Build Python Web Apps with Streamlit explains primary key →

Grokking Software Architecture

A relational database key that uniquely identifies each row in a table and cannot contain a null value.

How it is used
Uses primary keys to distinguish rows and avoid acting on the wrong record.
How deep it goes
Defines uniqueness and non-null requirements and explains relationships, without showing primary-key creation syntax.
Examples
Illustrates duplicate-name deletion and an Orders-to-Customers relationship.
What you can do after
Evaluate/understand how primary keys identify rows and support links between tables.

Read how Grokking Software Architecture explains primary key →

Kafka Streams in Action, Second Edition

A primary key is a field or set of fields that uniquely identifies a row in a database table.

How it is used
Uses primary keys to model KTable updates and choose valid aggregation and join strategies.
How deep it goes
Explains update semantics, regrouping, repartitioning, add/subtract aggregation, and foreign key extraction without defining database key constraints.
Examples
Uses user-profile updates, stock alerts grouped by market segment, and client contracts joined with commodity prices.
What you can do after
Apply it via Kafka Streams KTables to regroup records for aggregation and select direct or foreign key table joins.

Read how Kafka Streams in Action, Second Edition explains primary key →

Java Persistence with Spring Data and Hibernate epub

A primary key is a database column or set of columns whose values uniquely identify a row.

How it is used
Uses primary keys to connect relational row identity with persistent entity identity and collection mappings.
How deep it goes
Explains candidate-key selection, immutability constraints, and identity mismatches, while noting configurable generator strategies without detailing their configuration.
Examples
Illustrates a surrogate user ID with a unique username and a composite image-collection key containing the owner identifier.
What you can do after
Evaluate/understand key choices and identify potential stability or Java-equality problems in entity and collection mappings.

Read how Java Persistence with Spring Data and Hibernate epub explains primary key →

Effective Data Analysis

A primary key is a field or combination of fields that uniquely identifies a record in a dataset or table.

How it is used
Uses shared primary keys to connect datasets and identify relationships when assessing analytical scope or restructuring data.
How deep it goes
Defines identifiers and asks readers to identify keys for joins and schema design, without detailing database implementation.
Examples
Uses shared user or customer identifiers and a normalized startup schema containing customer, activity, address, product, and utility tables.
What you can do after
Apply primary keys to connect datasets, identify joins, and propose fact and dimension tables for analytical use.

Read how Effective Data Analysis explains primary key →

The Well-Grounded Python Developer: How the pros use Python and Flask

A primary key is a column or set of columns that uniquely identifies each record in a relational database table.

How it is used
Identifies records so normalized tables can reconnect through foreign keys and related application data can be loaded.
How deep it goes
Defines table-wide uniqueness, compares existing values with generated integers and UUIDs, and shows when loaded records receive keys.
Examples
Uses social security numbers, auto-incrementing integers, and a UUID-backed User model to illustrate identifier choices.
What you can do after
Apply it via SQLAlchemy by configuring a UUID-backed primary-key column and committing records before creating related orders.

Read how The Well-Grounded Python Developer: How the pros use Python and Flask explains primary key →

100 SQL Server Mistakes and How to Avoid Them

A primary key is a column or set of columns that uniquely identifies each row in a table.

How it is used
Uses primary keys to identify rows and connect related tables through foreign keys.
How deep it goes
Defines primary, foreign, natural, artificial, and composite keys, then demonstrates a typed primary-key declaration.
Examples
Uses EmployeeID, OfficeID, SocialSecurityNumber, and an employee-office relationship to illustrate primary-key choices.
What you can do after
Design primary-key columns, classify key choices, and define an employee identifier with SQL Server-style DDL.

Read how 100 SQL Server Mistakes and How to Avoid Them explains primary key →

Just Use Postgres!

A primary key is a column or set of columns that uniquely identifies each row in a table and cannot contain null values.

How it is used
Establishes row identity and protects database integrity in catalog, review, order, and order-item tables.
How deep it goes
Defines single-column, UUID, and compound keys with executable PostgreSQL table definitions, but defers broader key-design theory.
Examples
Uses catalog and review schemas, UUID-based orders, and order_items keyed by order_id and product_id.
What you can do after
Apply it via PostgreSQL CREATE TABLE definitions using numeric, UUID, or compound primary keys.

Read how Just Use Postgres! explains primary key →

AI-Powered Developer: Build software with ChatGPT and Copilot

A primary key is a column or set of columns that uniquely identifies each row in a relational table.

How it is used
Structures PostgreSQL tables and ORM models around stable row identifiers for an IT asset dataset.
How deep it goes
Defines primary-key columns, sequences, defaults, foreign-key links, and ORM mappings, but does not discuss composite-key design.
Examples
Uses depreciation_strategy, funding_details, and assets tables with integer ids and PostgreSQL sequences.
What you can do after
Build it from scratch by defining primary-key columns, attaching PostgreSQL sequences, and mapping identifiers in ORM classes.

Read how AI-Powered Developer: Build software with ChatGPT and Copilot explains primary key →

Spring in Action, Sixth Edition

A primary key is a Cassandra key definition that identifies rows and can combine partitioning and clustering components.

How it is used
Configures Cassandra-persisted domain classes by identifying rows and assigning partition and row-order responsibilities.
How deep it goes
Explains key annotations, partition placement, clustering order, and generated UUIDs through a Taco mapping.
Examples
Uses Ingredient and Taco mappings, including a UUID partition key, descending createdAt clustering key, and cqlsh output.
What you can do after
Configure Cassandra domain mappings with @PrimaryKey, @PrimaryKeyColumn, partitioning, clustering order, and UUID identifiers.

Read how Spring in Action, Sixth Edition explains primary key →

Build Financial Software with Generative AI (From Scratch)

A primary key is a column or set of columns that uniquely identifies each row in a relational table.

How it is used
Uses unique identifiers to organize ACH records and support relational storage, querying, and integrity.
How deep it goes
Defines primary keys as unique record identifiers and relates them to foreign keys and constraints, without detailing key-generation strategy.
Examples
Uses ACH files, batches, entries, addenda, UUID fields, and PlantUML table definitions to show identifier relationships.
What you can do after
Apply it via relational database design that identifies records and supports links between related ACH tables.

Read how Build Financial Software with Generative AI (From Scratch) explains primary key →

Building Web APIs with ASP.NET Core

A primary key is a property or column whose value uniquely identifies a record in an entity or table.

How it is used
Uses unique record identities to connect related entities in a fixed-schema SQL database.
How deep it goes
Defines uniqueness and demonstrates cross-table references, but stops short of explaining key-generation or constraint implementation.
Examples
Uses Users, Roles, BoardGames, Comments, and the Comments.BoardGameID reference as concrete schema examples.
What you can do after
Evaluate how a relational schema identifies records and represents relationships between tables.

Read how Building Web APIs with ASP.NET Core explains primary key →

.NET in Action, Second Edition

A primary key is a column or set of columns whose values uniquely identify rows in a database table.

How it is used
Identifies entity rows while EF Core generates relational tables from a code-first model.
How deep it goes
Explains convention-based and attribute-based configuration, stopping short of deeper database key behavior.
Examples
Uses a Book entity, a generated Books table, an Id property, and ISBN configured with Key.
What you can do after
Apply it via EF Core by following naming conventions or annotating a different identifying property.

Read how .NET in Action, Second Edition explains primary key →

Starting Data Analytics with Generative AI and Python

A primary key is a column or set of columns whose values uniquely identify records in a dataset.

How it is used
Anchors cross-reference validation by identifying the reference dataset and checking relationships among DataFrames.
How deep it goes
Explains reference and foreign-key relationships with customer, order, and payment examples, then stops short of resolving one violation.
Examples
Uses customer identifiers, order_id, customer orders, payment records, and a foreign-key violation check.
What you can do after
Diagnose broken references and unexpected dataset relationships by comparing foreign-key values with primary-key records.

Read how Starting Data Analytics with Generative AI and Python explains primary key →

Everyday Data Visualization

A primary key is a field whose value uniquely identifies each row in a table.

How it is used
Supports reliable identification of rows in tables containing observations such as visits, users, clicks, or transactions.
How deep it goes
Defines uniqueness, recommends integer identifiers, and notes alphanumeric alternatives without addressing database constraints or implementation.
Examples
Uses fruit IDs, Social Security numbers, driver’s license numbers, license plates, and vehicle identification numbers as examples.
What you can do after
Evaluate whether a table includes a unique identifier for every observation.

Read how Everyday Data Visualization explains primary key →

Learn Haskell by Example

A primary key is a column or set of columns whose values uniquely identify rows in a database table.

How it is used
Identifies Todo entries and constrains inserts, lookups, and updates in a SQLite-backed application.
How deep it goes
Defines declaration, automatic identifier creation, duplicate-insert failure, and identifier-based queries without exploring composite keys.
Examples
Uses an `entries` table with `id INTEGER PRIMARY KEY AUTOINCREMENT` and Haskell functions for insertion, lookup, and update.
What you can do after
Operate/configure SQLite schemas and handle duplicate identifiers during Haskell database operations.

Read how Learn Haskell by Example explains primary key →

Also covered in

What to know first

Related concepts

Questions about primary key

What is primary key?

A primary key is a field or combination of fields whose values uniquely identify each row or item in a data store.

Which Manning books explain primary key?

ScyllaDB in Action, Grokking Relational Database Design, Learn SQL in a Month of Lunches, DuckDB in Action, Amazon Web Services in Action, Third Edition: An in-depth guide to AWS, Functional Design and Architecture: Examples in Haskell, Build Python Web Apps with Streamlit, Grokking Software Architecture and 14 more.

What should I know before learning primary key?

Manning books that teach primary key usually introduce SQL, database table, universally unique identifier and foreign key first.

What kinds of primary key are there?

Kinds of primary key include composite key.

What is primary key part of?

Primary key is part of database table. A database table is a relational data structure that organizes records into rows whose values correspond to defined columns.

What are the parts of primary key?

Primary key includes partition key.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.