skip to content

questions

21

In a conceptual data model, how do you decide whether something like a customer's address should be modeled as an entity in its own right or as an attribute of the customer?

level: juniorimportance: must knowfreq 55%

answer

  1. identity, multiplicity, description, lifecycle
  2. attributes describe exactly one instance
  3. needs its own attributes -> entity
  4. shared or repeating -> entity
  5. same concept differs per domain

basics

~20 s

An entity is a thing with its own identity, its own describing facts and its own lifecycle. An attribute is one fact about a single entity instance. If addresses repeat, need describing, or are referenced on their own, model an entity.

solid answer

~50 s

I ask four questions. **Identity**: do I ever refer to this thing on its own, apart from its owner? **Multiplicity**: can one owner have several at once (home, billing, shipping)? **Description**: does the thing itself need attributes (validated flag, geocode, valid-from date)? **Lifecycle**: is it created, changed or removed independently, or shared between owners? Any yes pushes it toward being an entity; all no means it is just a group of attributes on Customer. In a simple retail model where each customer has exactly one address nobody else uses, address is a composite attribute — street, city, postcode grouped under one name. In a logistics model where addresses repeat, get validated and geocoded and are shared across customers and shipments, Address is an entity with its own relationships. The mistake is answering in the abstract: the same concept is an attribute in one domain and an entity in another, and only the domain decides.

go deeper

for a junior

Recall the definitions and give one clean example each way: birth date is an attribute, Customer is an entity, and address depends on whether it repeats.

for a middle

Lead with the tests — identity, multiplicity, own attributes, lifecycle — and show the same concept flipping between attribute and entity as the domain changes.

for a senior

Add the consequences: repeating columns and CSV fields when you under-model, join sprawl and unmaintained lookup tables when you over-model. Mention that the decision should come from business language.

for a principal

Frame it as scope control: entities are the things the organisation manages, audits and shares, so promoting one commits you to a lifecycle, ownership and often an API. Discuss deferring the promotion until the business actually manages the thing.

## The two building blocks A conceptual (ER) model describes what a business talks about, before any tables exist. An **entity** is a class of things with independent existence and identity — Customer, Order, Product, Flight. Identity means you can tell two instances apart and keep referring to the same one over time even as every fact about it changes. An **attribute** is a single descriptive fact belonging to exactly one entity instance — a customer's date of birth, an order's placed-at timestamp. Attributes have no life of their own: the value "blue" is meaningless until it is the colour of some car. ## The four tests **Identity.** Do you need to point at the thing independently — to list them, count them, correct one in place, or attach other things to it? Attributes are never pointed at; they are read through their owner. **Multiplicity.** Can one owner hold several values at the same time? A single-valued fact stays an attribute. Several simultaneous values means the thing is either a multivalued attribute or a separate entity. **Description.** Does the candidate need attributes of its own? The moment you want to record an address's verified-at timestamp or its latitude, it is behaving like an entity, because only entities have attributes. **Lifecycle and sharing.** Is it created and retired on a different schedule from its owner, or shared by more than one owner? Shared, independently-lived things are entities; anything that lives and dies exactly with its owner can be attributes. ## Worked example: address A payroll system stores one home address per employee, never searches by it, never validates it. Address is a **composite attribute**: a named group of simpler attributes (street, city, postcode) on Employee. A delivery system needs several addresses per customer, distinguishes their kinds, geocodes them, keeps the address a parcel was actually sent to even after the customer edits their profile, and reuses one warehouse address for thousands of shipments. Every test says entity. ## Relationships are not attributes A common error is listing "customer id" as an attribute of Order in the conceptual model. A link from one entity to another is a **relationship**, drawn as a line, not an attribute. Foreign key columns are an artifact of turning the model into tables, not part of the conceptual picture. Keeping them out is what lets you discuss cardinality honestly before committing to a physical shape. ## Why the call matters Under-modelling shows up as repeating groups — address1, address2, address3 — or comma-separated strings, both of which make querying and constraining the data awkward. Over-modelling shows up as a swarm of single-column satellite entities that add joins and buy nothing: promoting a status code to an entity when it has no attributes of its own, is never referenced independently, and never repeats, costs more than it returns unless the business really manages that list as data. ## How to decide quickly Ask the domain expert whether they ever talk about the thing on its own — "we deduplicate addresses", "we archive addresses" — or only ever as a property of something else. Business language is the strongest signal available at conceptual-modelling time, and it is far cheaper to change the model than the shipped schema.

  • Give an example where promoting a concept to an entity is the wrong call.
    A single-valued status code with no attributes of its own, never managed by the business as data, is best left as an attribute. Promoting it creates a one-column satellite that every query must join to, adds a lifecycle nobody maintains, and buys no new expressiveness. Promote it only if the business wants descriptions, ordering, or effective dates on the list.
  • Should the foreign key that links Order to Customer appear in the conceptual model?
    No. In the conceptual model that link is a relationship drawn between the two entities, with cardinality and optionality on it. Foreign keys are the physical device that implements the relationship once you map to tables. Adding them early hides the modelling question — whether an order may exist without a customer, and whether one customer may have many orders.

Colour is an attribute of a car; the paint shop that applied it is an entity — you can visit it, describe it, and other cars point at it.

saying these in an interview costs you the question

  • Claiming address is always an entity (or always an attribute) regardless of the domain
  • Listing foreign keys such as customer_id as conceptual attributes of the entity
  • Treating anything that gets its own table as an entity, so the answer becomes circular
  • Promoting every code list to an entity for its own sake, adding joins with no attributes behind them
  • Confusing an attribute with a column type decision — conceptual modelling is not about VARCHAR sizes

context

open as a page

A model says a student may enrol in many courses and a course may hold many students. How is that many-to-many association represented in relational tables, what is the extra table's key, and why can it not be done with a column on either side?

level: juniorimportance: must knowfreq 70%

basics

~20 s

It becomes a third table holding one row per pair — student key and course key — with a foreign key to each parent and a primary key over the pair. Neither parent can hold the link because each side has many partners, and a column stores only one value.

open as a page

An entity in your model has an attribute that can hold several values at once, such as a customer's phone numbers. How is that mapped to relational tables, and why not use repeated columns or one comma-separated string?

level: juniorimportance: must knowfreq 50%

basics

~20 s

It becomes a child table holding the owner's key plus one value per row, with a foreign key to the owner and a key over (owner key, value). Repeated columns cap the count and scatter one fact; a delimited string loses typing, constraints and lookups.

open as a page

How do you store a tree structure (for example an organizational chart or a category tree) in a relational table using a self-referencing foreign key, and how do you retrieve a whole subtree from it?

level: juniorimportance: must knowfreq 72%

basics

~20 s

Give the table a parent_id column that is a foreign key back to its own primary key. Roots have NULL parent_id. One row per node stores one edge. To read a whole subtree you walk the parent_id chain repeatedly, which in standard SQL means a recursive query.

open as a page

How do you implement a many-to-many relationship between two tables in a relational database, and why can't a single foreign key column express it?

level: juniorimportance: must knowfreq 82%

basics

~20 s

Use a third table holding one foreign key to each side, keyed on the pair of them. A single foreign key column stores one value per row, so it cannot record many links from the same row.

open as a page

In a one-to-many relationship such as customers and orders, which table gets the foreign key column, and how do you model whether the child row is allowed to exist without a parent?

level: juniorimportance: must knowfreq 74%

basics

~10 s

The foreign key goes on the many side: orders holds customer_id referencing customers. If every child must have a parent, declare it NOT NULL; if it may stand alone, allow NULL. Index that column.

open as a page

When describing a relationship between two entities in a data model, what is the difference between its cardinality and its optionality (participation), and what does each tell you about the data?

level: middleimportance: must knowfreq 65%

basics

~20 s

Cardinality is the maximum: how many instances on the other side one instance may relate to (1:1, 1:N, M:N). Optionality is the minimum: whether an instance must participate at all (zero or at least one). Together they read as a (min, max) pair per side.

open as a page

Walk through the standard algorithm for turning a finished entity-relationship diagram into a set of relational tables: what does each construct — entity, attribute, relationship — become?

level: middleimportance: must knowfreq 55%

basics

~20 s

Each strong entity becomes a table keyed by its own key. Composite attributes become their component columns. Multivalued attributes become child tables. Weak entities become tables keyed by owner key plus discriminator. One-to-many relationships become a foreign key on the many side; many-to-many becomes its own table.

open as a page

You have a supertype entity with several subtypes that share common attributes and each add their own — for example Payment with CardPayment, BankTransfer and Voucher. What are the standard ways to map that into relational tables, and what does each one cost?

level: middleimportance: must knowfreq 62%

basics

~20 s

Three options. Single table: one table with all columns plus a type discriminator; subtype columns must be nullable. Class table: a parent table for shared columns and one child table per subtype sharing the parent's primary key; reads join. Concrete table per subtype: one independent table per subtype with the shared columns repeated; no join, but no single place holding all payments.

open as a page

In entity-relationship modeling, what do the terms simple, composite, multivalued and derived attribute mean? Give an example of each.

level: juniorimportance: should knowfreq 40%

basics

~20 s

Simple: one atomic value (birth date). Composite: a named group of simpler parts (full name = first + last). Multivalued: several values at once for one instance (phone numbers). Derived: computable from other stored data (age from birth date).

open as a page

What is a weak entity in entity-relationship modeling, and how does it differ from an ordinary entity that merely has a mandatory reference to another entity?

level: middleimportance: should knowfreq 40%

basics

~20 s

A weak entity cannot be identified by its own attributes: it is identified only together with its owner, through an identifying relationship, using a partial key that is unique only within that owner. It also depends on the owner for existence.

open as a page

When a relationship itself carries data — the date an employee was assigned to a project, or the quantity on an order line — which table does that data end up in once the model is mapped to relational tables, and how does the answer depend on the relationship's cardinality?

level: middleimportance: should knowfreq 45%

basics

~20 s

The attribute follows wherever the relationship landed. For one-to-many it becomes a column on the many-side table, next to the foreign key. For many-to-many it becomes a column in the junction table. For one-to-one it goes on whichever side holds the foreign key.

open as a page

How do you map a weak entity — one whose instances are identified only inside an owner, such as a line within an invoice — into a relational table, and what is that table's primary key?

level: middleimportance: should knowfreq 38%

basics

~20 s

It becomes its own table whose primary key is the owner's primary key plus the weak entity's discriminator (for example invoice_id plus line_no). The owner-key columns are also a foreign key to the owner, declared not null because the dependency is mandatory.

open as a page

What is a closure table for storing hierarchical data, what rows does it contain, and what does it cost to insert or move a node?

level: middleimportance: should knowfreq 48%

basics

~20 s

A closure table is a separate table holding one row for every ancestor-descendant pair, including each node paired with itself, usually with the distance between them. Any ancestor or descendant query becomes one indexed lookup. Writes cost many rows: inserting a node adds one row per ancestor, and moving a subtree rewrites all pairs crossing the moved boundary.

open as a page

For a link table holding two foreign keys, how do you choose between a composite primary key on those keys and a separate surrogate id, and what indexes does the table need so lookups are fast from both sides?

level: middleimportance: should knowfreq 48%

basics

~20 s

Composite primary key on both foreign keys is the default: it blocks duplicate pairs and indexes the pair. Add a second index on the reversed order for the other direction. Use a surrogate id only when the link itself is referenced or may repeat.

open as a page

What are the ways to implement a one-to-one relationship between two tables, and when is splitting the attributes across two tables worth it instead of keeping one wider table?

level: middleimportance: should knowfreq 50%

basics

~20 s

Either share the primary key — the child's primary key is also a foreign key to the parent — or put a unique foreign key on one side. Split only for optional, bulky, rarely read, or separately secured attributes.

open as a page

When would you model an association among three entities as a single three-way (ternary) relationship rather than as three separate two-way relationships, and what does each choice assert about the data?

level: seniorimportance: should knowfreq 28%

basics

~20 s

Use a ternary relationship when a fact is only meaningful as a triple — supplier supplies part to project — and cannot be reconstructed from the three pairs. Use separate binary relationships when each pair is an independent fact. Ternary asserts more; binaries assert less.

open as a page

Compare the four common ways to store a tree in a relational database — parent pointers, a materialized path string, nested sets with left/right numbering, and an ancestor-descendant pairs table — and explain how you would choose between them for a category tree that is read constantly and edited occasionally.

level: seniorimportance: should knowfreq 42%

basics

~20 s

Parent pointers: cheapest writes, traversal needs recursion. Materialized path: stores the ancestor chain in a string, fast downward prefix reads, rewrites the whole subtree on a move. Nested sets: left/right numbers make subtree reads one range scan but almost any insert renumbers much of the table. Pairs table: fast both directions, expensive writes and O(n×depth) storage. Read-heavy, edit-rarely favors path or pairs.

open as a page

A production table maps a supertype and its subtypes into one wide table with a type discriminator; it now has 40 nullable columns, 9 subtypes, and every new subtype requires altering that table. How would you evaluate whether to restructure it into a parent table with per-subtype child tables, and what would the migration and the resulting query costs look like?

level: seniorimportance: should knowfreq 34%

basics

~20 s

Measure first: which queries are polymorphic, which are subtype-specific, how sparse the columns are, and how often subtypes are added. Restructure to a parent plus child tables when subtype columns dominate and integrity matters. Migrate by backfilling child tables from the wide table, dual-writing, cutting reads over, then dropping columns. Polymorphic reads gain a join; subtype reads get narrower and better-indexed.

open as a page

Where do attributes that describe a relationship itself belong — for example a student's grade in a course, or the date a user joined a team — and how does the model change when that relationship has to keep history?

level: seniorimportance: should knowfreq 40%

basics

~20 s

They belong on the junction row, because they depend on both sides and on neither alone. Once the same pair can recur over time, add validity dates to the key or a surrogate key, and the link becomes an entity with its own lifecycle.

open as a page

How do you map a three-way (ternary) relationship — for example which supplier supplies which part to which project, with a quantity — into relational tables, and what should that table's key be?

level: seniorimportance: nice to knowfreq 25%

basics

~20 s

It becomes one table holding all three participants' primary keys as foreign keys, plus the relationship's own attributes. The default primary key is all three key columns together; cardinality constraints can narrow it to a subset, and repetition over time adds a component.

open as a page