Chapter 1

Relational foundations and ER modelling

Start with what a row represents and what uniquely identifies it. ER constraints describe the real-world associations; keys and foreign keys express part of those constraints in tables.

1.1 Relations, schemas and database levels

Past papers · CS 2014–2026 (23 papers): 2 questions, 2 marks

A relation schema R(U)R(U) names an attribute set UU and its domains. An instance rr is a finite set of tuples over those domains. Degree or arity is the number of attributes; cardinality is the number of tuples. Attribute order and tuple order have no logical significance. SQL tables may contain duplicate rows; a mathematical relation cannot.

LevelDescribesIndependence
ExternalA user's view of selected dataDifferent users can see different views
Conceptual or logicalRelations, attributes and constraintsLogical changes can be hidden from external views
Internal or physicalFiles, blocks and indexesPhysical changes can be hidden from the logical schema

A view is a named query; an ordinary view need not store its result. A materialised view does store results and must be maintained when base data changes. Changing an index is a physical change; adding a relation is a logical change.

1.2 Keys and superkey counting

Past papers · CS 2014–2026 (23 papers): 6 questions, 7 marks

A superkey uniquely determines every attribute in all legal instances. A candidate key is an inclusion-minimal superkey: removing any one of its attributes destroys that property. Minimal does not mean smallest cardinality among all keys. The primary key is one chosen candidate key; the remaining candidate keys are alternate keys. An attribute is prime if it belongs to at least one candidate key.

An instance with no duplicate values does not prove a schema-level key. To disprove a proposed key in an instance, find two distinct rows agreeing on its columns.

1.3 Integrity and referential actions

Past papers · CS 2014–2026 (23 papers): 3 questions, 3 marks · DA 2024–2026 (3 papers): 2 questions, 3 marks

Domain constraints restrict allowed values. Key constraints restrict duplication. Entity integrity disallows NULL in every component of the primary key. Referential integrity requires a non-null foreign-key value to match a referenced candidate/unique key. A foreign key need not be unique and may refer to the same table. A table can have several foreign keys.

For a composite reference, compare the entire tuple of referencing columns, in corresponding order. One component of a composite primary key is not automatically a legal target on its own. Under the usual SQL MATCH SIMPLE, any null component exempts that row from the matching requirement; NOT NULL rules still apply. MATCH FULL permits either all-null components or a completely non-null matching tuple.

OperationPossible foreign-key problem
Insert child; update child's foreign keyNew reference may have no parent
Delete parent; update referenced keyExisting children may lose their parent
Insert parent; delete childCannot by itself create an orphan for this particular reference
Parent actionEffect on referencing rows
RESTRICTReject the change when references block it
NO ACTIONCheck the constraint at its configured checking time; not a synonym for ignoring it
CASCADEDelete children on parent deletion; propagate the changed key on update
SET NULLKeep children and null the referencing columns, if allowed
SET DEFAULTUse defaults; the resulting reference must still be valid

1.4 ER symbols, cardinality and participation

Past papers · CS 2014–2026 (23 papers): 4 questions, 4 marks

An entity is distinguishable in the model; a relationship links entities in named roles. A recursive relationship uses the same entity type more than once, so role names matter. A relationship can have attributes of its own. A ternary relationship is generally not equivalent to three binary relationships: the allowed triples may be lost.

Chen notationMeaning
Rectangle / diamondEntity set / relationship set
Oval; underlined attributeAttribute; key attribute
Oval with component ovalsComposite attribute
Double oval / dashed ovalMultivalued / derived attribute
Double rectangle / double diamondWeak entity / identifying relationship
Double participation lineEvery entity on that side participates

For E1 ⁣: ⁣E2E_1\!:\!E_2 as many-to-one, each E1E_1 entity has at most one partner in E2E_2. Total participation of E1E_1 changes “at most one” to “exactly one”. Total participation of E2E_2 requires at least one incoming partner; it does not impose uniqueness.

A weak entity is identified by its owner's key together with its partial key, also called discriminator. Its participation in the identifying relationship is total; the owner's need not be. Partial keys are commonly drawn with dashed underlining.

1.5 Converting ER models to relations

Past papers · CS 2014–2026 (23 papers): 2 questions, 3 marks · DA 2024–2026 (3 papers): 1 question, 2 marks

ER constructRelational representation
Strong entityOne relation with its key and simple attributes; flatten composite attributes
Weak entityOwner key plus partial key form the primary key; include weak entity attributes
Multivalued attributeSeparate relation with owner key and the attribute value; their combination identifies values
Many-to-onePut the one-side key as a foreign key in the many-side relation; place relationship attributes there
One-to-oneA foreign key with UNIQUE on a suitable side; prefer a total-participation side to avoid nulls
Many-to-manySeparate relation containing both entity keys and relationship attributes
Ternary or higher relationshipSeparate relation; determine its key from the actual cardinality constraints

For a many-to-one mapping, total participation of the many side permits a non-null foreign key and removal of a separate relationship table. Partial participation needs nullable references or a separate relationship relation. Total participation on both sides of a many-to-many relationship does not remove the need for its association table when the final design must remain in 3NF and no extra dependencies are given.

Specialisation inherits the superclass key and attributes. A superclass table plus one table per subclass is a general mapping: each subclass key is also a foreign key to the superclass. Disjoint/overlapping and total/partial constraints require separate enforcement; tables alone do not automatically enforce all of them.

Last-minute recall

  • Degree counts columns; cardinality counts rows.
  • A candidate key is minimal by inclusion; a superkey may contain extra attributes.
  • Prime means present in at least one candidate key.
  • A foreign key need not be a key in its own table.
  • Cardinality gives the maximum; participation gives the minimum.
  • A weak entity needs its owner key and partial key.
  • Multivalued attributes and many-to-many associations normally need separate tables.

Revise offline: the whole Databases and Data Warehousing handbook as one PDF

58 pages · 2.7 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections