Top Banner
Relational Model Contents: 1.What is relational model What is the use of relational model 2. Relational model 1. Structural part; 2. Integrity part; 3. Manipulative part (Next Week)
24

Relational Model

Dec 31, 2015

Download

Documents

whitney-osborn

Relational Model. Contents:. What is relational model What is the use of relational model 2. Relational model 1. Structural part; 2. Integrity part; 3. Manipulative part (Next Week). 2.1 Relational Model. A relational model includes three parts:. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Relational Model

Relational Model

Contents:

1. What is relational model What is the use of relational model2. Relational model

1. Structural part;2. Integrity part;3. Manipulative part (Next Week)

Page 2: Relational Model

2.1 Relational Model

A relational model includes three parts:

a) Structural part, a collection of the type of structures;

b) Manipulative part, operations used on databases;

c) Integrity part, rules that databases must obey.

Page 3: Relational Model

2.2 The Use

It is basis for designing relational RDBMSs.1) The designer to reason about the database

systems without actually having build them;2) An RDBMS implements the structures, oper

ations and rules of the relational model.

Page 4: Relational Model

2.3 The structural part Component of the structural part:

Domains Attributes; Relations; Keys.

Book_Title Authors Published date Price

Relational Databases BEA 2000.5 12.35

Java EFH 2001.2 16.50

       

Relational database: is made up of relations.

Relation: is a structure describing the relationships between things in the real world.

Page 5: Relational Model

2.3 The structural part

Book_Title Authors Published date PriceRelational Databases BEA 2000.5 12.35

Java EFH 2001.2 16.50

       

Column::attributeTable::Relation

Row::Tuple

The table – relations;

The columns – attributes;The column headings – attribute names;The values in the column – attribute values.

The rows -- tuples.

??

Page 6: Relational Model

2.3 The Structural Part Example: to understand the concepts

Prod_No Name Colour

P1 Pantaloons Blue

P3 Socks Harebell

P4 Socks White

Warehouse

Warehouse_No Location

WH1 Leeds

WH2 Bradford

Stock

Warehouse_No Prod_No Quantity

WH1 P1 5000

WH1 P3 10000

WH1 P4 10000

WH2 P3 20000

WH2 P4 5000

Product

What can you see From these tables?

Page 7: Relational Model

2.3 The Structural Part Concepts: Relations, attributes and tuples

• A relational database -- a number of relations (tables).

• A relation is made up of tuples (rows) each of which is a set of domain values.

• An attribute is given a name,

• Each attribute must take a value from the domain.

• ---- what is domain?

Page 8: Relational Model

2.3 The Structural Part Domain: an attribute in a relational

database is defined on a domain. Prod_No Name Colour

P1 Pantaloons Blue

P3 Socks Harebell

P4 Socks White

Domain of Prod_No:{P1, P2, P3}

Domain of Name:{Pantaloons, Socks}

–A domain is a set of values from which the values of one or more attributes are taken.–Every value in a database must be a member of some domain;–Domain values must be single-valued.–Examples 2.2-2.8.

Page 9: Relational Model

2.3 The Structural PartConcept: Key

HOW to distinguish each PRODUCT?

Prod_No Name Colour

P1 Pantaloons Blue

P3 Socks Harebell

P4 Socks White

Need to define a Key?

Page 10: Relational Model

2.3 The Structural Part Example: the keys

Prod_No Name Colour

P1 Pantaloons Blue

P3 Socks Harebell

P4 Socks White

Warehouse

Warehouse_No Location

WH1 Leeds

WH2 Bradford

Stock

Warehouse_No

Prod_No Quantity

WH1 P1 5000

WH1 P3 10000

WH1 P4 10000

WH2 P3 20000

WH2 P4 5000

Product

Keys:• Product: Prod_No.• Warehouse: Warehouse_No, or Location.• Stock: Warehouse_NO and Prod_No.

Page 11: Relational Model

2.3 The Structural Part

• Keys are used to represent the names of the things.

• A key is one or more attributes of a relation.

Concept: Key

• The value of a key uniquely identify each tuple.

Page 12: Relational Model

2.3 The Structural Part• Note 1 the key for STOCK is made up of two attributes, but a

ny one of them is not key.

• Super-key: key + other attributes, e.g., Warehouse_NO+Prod_No, + Quantity.

Warehouse_No Location

WH1 Leeds

WH2 Bradford

Prod_No Name Colour

P1 Pantaloons Blue

P3 Socks Harebell

P4 Socks White

Warehouse_No Prod_No Quantity

WH1 P1 5000

WH1 P3 10000

WH1 P4 10000

WH2 P3 20000

WH2 P4 5000

Page 13: Relational Model

2.3 The Structural Part

Note 2 A relation may have many keys--called candidate keys.

Every relation has at least one candidate key. One candidate key is selected as the primary key. The candidate keys not selected as the primary k

ey are called alternate keys.

Warehouse_No Location

WH1 Leeds

WH2 Bradford

Keys:• Warehouse: Warehouse_No, or Location.

Page 14: Relational Model

2.3 The Structural Part

A foreign key: attributes whose values are used elsewhere as primary key values. Prod_No: a primary key in Product, A foreign key in Stock.

• A primary key is selected so that we can make sure that each tuple has some unique identifier.

• The attributes of primary key are not allowed to have no value at all.

•The primary key and foreign key are defined on the same domain but not necessary have the same attribute names.

Page 15: Relational Model

2.3 The Structural Part Table 2.1: summary- relation

Relational Structure Table Files

Relation Table File

Tuple Row Record

Attribute Column Field

Attribute name Column heading Field name

Attribute value Table entry Data items

Page 16: Relational Model

2.3 The Structural Part

Summary – relational model:• Database. A relational database comprises a set of table-li

ke structures called relations.

• Relation. A relation is like a table of values, in which no two rows can be identical.

• Attributes. A relation is defined on a number of attributes. Each attribute has one name and the attribute value represent facts.

• Domain. A domain is a set of values that represent all the facts. Each attribute takes values from a particular domain.

Page 17: Relational Model

2.3 The Structural Part Summary – relational model

• Tuple. A relation is a set of tuple. Each tuple is a set of attribute values, one for each attribute of the relation.. A tuple represents a proposition.

• Key. A key is a set of attributes whose values uniquely name each tuple of relation.

• Super-key is a key plus some other attributes.

• candidate keys, primary key, alternate keys, foreign keys.

Page 18: Relational Model

2.4 The integrity part

What is the integrity part

A set of rules that the Relational Database must obey.

Page 19: Relational Model

2.4 The integrity part

What are the rules

Only two general rules:

1. Entity integrity rules

2. Referential rules

Page 20: Relational Model

2.4 The integrity part

Entity Integrity Rules

Each tuple must include a unique name or identifier.

i.e. The primary key must have a non-null value.

Page 21: Relational Model

2.4 The integrity part

Referential Integrity Rules

 

All cross-referenced objects must be within the database.

Error!! If you have added the sales order of

Customer C9, but forget adding record of C9!

Page 22: Relational Model

2.4 The integrity part

What referential integrity rules is?

 

The foreign key value must be either NULL or a value that occurs elsewhere as A PRIMARY KEY.

Page 23: Relational Model

2.4 The integrity part

ExampleCustomer

Cust_No Name Address

C45 Boys Newsome

C46 Girls Holey

Order_No Date Cust_No

011 1/7/89 C45

012 1/8/89 Null

013 2/5/88 C47

null 1/1/89 C45

Sales_Order

Anything wrong in this database?

Page 24: Relational Model

2.4 The integrity part Summary

1. Integrity part includes two rules: Entity rule; Integrity rule;

2. They ensure, respectively, All data objects have names No object cross-refer a non-existent

data object.