Relational Model

COMP3311 20T3 ♢ Rel Model ♢ [0/13]
❖ Relational Data Model

The relational data model describes the world as

The relational model has one structuring mechanism: relations Each relation (denoted R,S,T,...) has: Each attribute (denoted A,B,... or a1,a2,...) has:
COMP3311 20T3 ♢ Rel Model ♢ [1/13]
❖ Relational Data Model (cont)

Consider relation R with attributes a1, a2, ... an

Relation schema of R :   R(a1:D1, a2:D2, ... an:Dn)

Tuple of R : an element of D1 × D2 × ... × Dn   (i.e. list of values)

Instance of R : subset of D1 × D2 × ... × Dn   (i.e. set of tuples)

Note:   tuples: (2,3)  ≠  (3,2)     relation: { (a,b), (c,d) }  =  { (c,d), (a,b) }

Domains are comprised of atomic values   (e.g. integer, string, date)

A distinguished value NULL belongs to all domains

Each relation has a key   (subset of attributes unique for each tuple)

COMP3311 20T3 ♢ Rel Model ♢ [2/13]
❖ Relational Data Model (cont)

A relation:   Account(branchName, accountNo, balance)

And an instance  of this relation:

{
  (Sydney, A-101, 500),
  (Coogee, A-215, 700),
  (Parramatta, A-102, 400),
  (Rouse Hill, A-305, 350),
  (Brighton, A-201, 900),
  (Kingsford, A-222, 700)
  (Brighton, A-217, 750)
}

Note: accountNo is a primary key.

COMP3311 20T3 ♢ Rel Model ♢ [3/13]
❖ Relational Data Model (cont)

Account relation as a table:

[Diagram:Pics/er-rel/rel-table.png]

COMP3311 20T3 ♢ Rel Model ♢ [4/13]
❖ Example Database Schema

Consider the following ER data model:


[Diagram:Pics/er-rel/schemaER.png]

COMP3311 20T3 ♢ Rel Model ♢ [5/13]
❖ Example Database Schema (cont)

Relational schema derived from this ER model:


[Diagram:Pics/er-rel/schema.png]


Note: distinguish attributes via e.g. Branch.address vs Customer.address

COMP3311 20T3 ♢ Rel Model ♢ [6/13]
❖ Example Database (Instance)

[Diagram:Pics/er-rel/rel-tables.png]

COMP3311 20T3 ♢ Rel Model ♢ [7/13]
❖ Integrity Constraints

To represent real-world problems, need to describe

Constraints are logical statements that do this:
COMP3311 20T3 ♢ Rel Model ♢ [8/13]
❖ Integrity Constraints (cont)

Domain constraints example:

Note: NULL satisfies all domain constraints   (except (NOT NULL))

Key constraints example:

Entity integrity example:

COMP3311 20T3 ♢ Rel Model ♢ [9/13]
❖ Referential Integrity

Referential integrity constraints

Example:

[Diagram:Pics/er-rel/fkeys.png]

COMP3311 20T3 ♢ Rel Model ♢ [10/13]
❖ Referential Integrity (cont)

A set of attributes F  in relation R1  is a foreign key for R2  if:

Foreign keys are critical in relational DBs; they provide ...
COMP3311 20T3 ♢ Rel Model ♢ [11/13]
❖ Relational Databases

A relational database schema is

A relational database instance is One of the important functions of a relational DBMS: Changes to the data fail if they would cause constraint violation
COMP3311 20T3 ♢ Rel Model ♢ [12/13]
❖ Describing Relational Schemas

We need a language to express relational schemas
(which is more detailed than boxes-and-arrows diagrams used above)

SQL provides a Data Definition Language (DDL) for this.

CREATE TABLE TableName (
   attrName1 domain1 constraints1 ,
   attrName2 domain2 constraints2 ,
   ...
   PRIMARY KEY (attri,attrj,...),
   FOREIGN KEY (attrx,attry,...)
               REFERENCES
               OtherTable (attrm,attrn,...), ...
);

To be continued ...
COMP3311 20T3 ♢ Rel Model ♢ [13/13]


Produced: 15 Sep 2022