Data Modeling and SQL
-
Tables, Rows, and Columns in SQL
A table organizes rows around named columns. Each row describes one occurrence or relationship under the table's design.
-
Primary Keys and Display Names
A primary key identifies rows uniquely and excludes null components under SQL primary-key semantics. A display name may be shared or change.
-
Foreign Keys as References Between Tables
A foreign key checks that a referenced value has a corresponding key under the declared relational constraint, with rules for nulls and changes.
-
A Composite Key in a Table
A composite key identifies a row through several columns together. Each individual column can repeat when the full combination must remain unique.
-
Column Types and Business Rules
A column type controls representable values. A domain constraint can restrict values further according to what the application means.
-
Null, Zero, and Empty Text in SQL
SQL null indicates missing or unknown data under the applicable operation. Zero and empty text can be present values with distinct meanings.
-
Requiring a Present Column Value
A not-null constraint requires a column value to be present. It does not by itself require a nonempty string or a value in a particular interval.
-
Defaults for Omitted Column Values
A column default supplies a value under the database's insertion rules when the caller requests a default or omits that column.
-
Uniqueness for a Column or Combination
A uniqueness constraint gives the database responsibility for rejecting duplicate keys according to its rules.
-
Checking an Explicit Row Condition
A check constraint can enforce a Boolean condition over a row's values according to the database's constraint evaluation rules.
-
One-to-Many Relationships in Tables
A one-to-many relationship allows several rows to reference one parent while each child row uses a single reference for that role.
-
Many-to-Many Relationships with a Link Table
A link table stores each relationship as a separate row, allowing each side to occur in several pairs.
-
One-to-One Relationships with a Unique Reference
A foreign key with a uniqueness constraint can limit the number of rows pointing at a parent to at most one.
-
Choosing What One Table Row Represents
Row granularity says what one observation or entity in a table means. Measures and keys depend on that choice.
-
Moving a Repeated Attribute into a Related Table
A separate table can keep repeated facts in one authoritative location and let several rows refer to them.
-
Generated IDs and Domain Keys
A generated ID can supply durable row identity. A domain key represents a naturally occurring uniqueness rule in the application.
-
Why Generated Row Numbers Can Have Gaps
A sequence or identity mechanism can supply distinct values without promising that every integer appears in saved rows.
-
Units and Scales in Database Columns
A column name or companion field can specify what stored numeric values measure. Conversions belong at documented interfaces.
-
Saving Decimal Amounts with a Currency and Scale
A monetary value needs a currency, a scale, and a rounding contract. A fixed-scale decimal or lowest-unit integer can serve different domains.
-
Storing an Instant or a Local Calendar Date
A timestamp used for ordering observations and a date used for a local policy encode different information. Column choice should match that intent.
-
Enumerated Status Values and Reference Tables
A small fixed status set can be constrained directly. A reference table can give allowed statuses additional data and an independent lifecycle.
-
Deletion Policies for Referenced Rows
A relationship constraint defines what happens to referencing rows when someone removes a referenced row.
-
Creating Related Rows as One Unit of Work
An operation creating a parent and children can make their changes succeed or fail together when the application promises a complete result.
-
Introducing a Database Column for Existing Rows
A schema change must account for data created before the new column existed and for writes occurring during rollout.
-
Adding a Uniqueness Rule to Existing Data
Before enforcing uniqueness, examine which current rows would share a key and decide which changes preserve the domain's relationships.
-
Selecting the Intended Rows for an Update
A database update uses a predicate to choose which rows to change. The predicate should express the operation's exact scope.
-
Current Rows and Historical Events
A current row can record the latest state. An event table can retain selected transitions when the history itself matters.
-
Reference Codes and Human Labels in Tables
A reference record can carry a stable code used by software and one or more labels used for display.
-
Combining Column Defaults and Checks
A default supplies a value under its rules. A check enforces a condition when candidate rows are stored. Choose them to agree at the insertion boundary.
-
Designing Tables from the Questions They Need to Answer
A usable schema records enough identity, relationships, and measurement detail to answer representative queries accurately.