You are on page 1of 23

Logical Database Model:

Relational Database
The Relational Model

Relational Model [Properties]


– Each relation (or table) in a database has a unique
name
– An entry at the intersection of each row and column is
atomic (or single-valued);
there can be no multi-valued attributes in a relation
– Each row is unique;
no two rows in a relation are identical
– Each attribute (or column) within a table has a unique
name
The Relational Model

Properties Cont’d
– The sequence of columns (left to right) is insignificant;
the columns of a relation can be interchanged without
changing the meaning or use of the relation
– The sequence of rows (top to bottom) is insignificant;
rows of a relation may be interchanged or stored in
any sequence
The Relational Model...
 The
relational model of data has three major
components:

− Relational database objects


− allows to define data structures
− Relational operators
− allows manipulation of stored data
− Relational integrity constraints
− allows to defines business rules and ensure
data integrity
The Relational Objects
 Location
Most RDBMS can have multiple
locations, all managed by the
same database engine Accounting

Accounts Accounts
Receivable Payable

Corporate Database
Accounting
Marketing

Sales Advertising Marketing Purchasing


 Database

– A set of SQL objects


The Relational Objects...
Database Server
Update Trigger
BEGIN
Client Application Table T
...
UPDATE T SET Insert Trigger
BEGIN
INSERT INTO T ...
DELETE FROM T Delete Trigger
CALL STPROG Stored Table A BEGIN
Procedure ...
BEGIN Table B
...
The Relational Objects...
 Database

– A collection of tables and associated indexes

Index

Table Table
Employee Product

Table Table
Files
Department Customer
The Relational Objects...

 Relation

– A named, two dimensional table of data


 Database
– A collection of databases, tables and
related objects organised in a structured
fashion.
– Several database vendors use schema
interchangeably with database
Relational Objects...

Data is presented to the user as tables:

Tables are comprised of rows and a fixed


number of named columns.
Table
Column 1 Column 2 Column 3 Column 4
Row

Row
Row
Relational Objects...
Data is presented to the user as tables:

Columns are attributes describing an entity. Each column


must have an unique name and a data type.
Employee
Name Designation Department
Row

Row
Row
Structure of a relation (e.g. Employee)
Employee(Name, Designation, Department)
Relational Objects...
Data is presented to the user as tables:

Rows are records that present information


about a particular entity occurrence
Employee
Name Designation Department
Row De Silva Manager Personnel
Row Perera Secretary Personnel
Row Dias Manager Sales
Relational model terminology
 Row is called a ‘tuple’:Column header called an
‘attribute’
 Table is called a ‘relation’
 The data type describing the type of values that can
appear in each column is called a ‘domain’
 Eg:-Names : the set of names of persons
– Employee_ages : value between 15 & 80 years old

The above is called ‘logical definitions of domains’.


A data type or format can also be specified for each
domain.
Eg: The employee age is an integer between 15 and 80
Characteristics of relations

 Ordering of tuples
– Tuples in a relation don’t have any particular order.
However in a file they may be physically ordered
based on a criteria, this is not there in relational model

 Values in a tuple are atomic


Relational constraints
 Domain constraints
– specifies that the value of each attribute ‘A’ must be an
atomic value. And from the specified domain

 Key constraints
– There is a sub set of attributes of a relational schema with
the property that no two tuples should have the same
combination of values for the attributes.
– If a relation has more than one key, they are called
candidate keys
– One of them is chosen as the primary key
Relational Objects
Keys

Primary Key: An attribute (or combination of


attributes) that uniquely identifies each row in a
relation.
Employee(Emp_No, Emp_Name, Department)
Composite Key: A primary key that consists of
more than one attribute
Salary(Emp_No, Eff_Date, Amount)
Relational Objects
Data is presented to the user as tables:

Each table has a primary key. The primary key is a


column or combination of columns that uniquely identify
each row of the table.
Employee Salary
E-No E-Name D-No E-No Eff-Date Amt
179 Silva 7 179 1/1/98 8000
857 Perera 4 857 3/7/94 9000
342 Dias 7 179 1/6/97 7000
Primary Key 342 28/1/97 7500
Primary Key
Relational Objects
Data is presented to the user as tables:

The cardinality of a table refers to the


number of rows in the table. The degree
of a table refers to the number of columns.
Salary
E-No Eff-Date Amt
Salary Table
Degree =3 179 1/1/98 8000
857 3/7/94 9000
Cardinality = 4
179 1/6/97 7000
342 28/1/97 7500
Relational Objects
Relationship

Foreign Key: An attribute in a relation of a database


that serves as the primary key of another relation in the
same database
Employee(Emp_No, Emp_Name, Department)
Department(Dept_No, Dept_Name, M_No)

=== works for ==>


Relational Objects
Data is presented to the user as tables:

Employee Department
E-No E-Name D-No D-No D-Name M-No
179 Silva 7 4 Finance 857
857 Perera 4 7 Sales 179
342 Dias 7 Primary Key
Primary Key Foreign Key

A foreign key is a set of columns in one table


that serve as the primary key in another table
Department
Relational Objects... D-No D-Name M-No

Employee 4 Finance 857


E-No E-Name D-No 7 Sales 179
Primary
Primary Key
Key Foreign Key
179 Silva 7
857 Perera 4
342 Dias 7
Primary Key Foreign Key Salary
E-No Eff-Date Amt
179 1/1/98 8000
857 3/7/94 9000
Rows in one or more tables are 179 1/6/97 7000
associated with each other solely 342 28/1/97 7500
through data values in columns Foreign Key
(no pointers). Primary Key
Relational Objects
 Index
– An ordered set of pointers to the data in the table

Improves performance. Access to data is faster

Employee
E-Name Pointer E-No E-Name D-No
De Silva 179 Silva 7
Dias 857 Perera 4
Perera 342 Dias 7
Silva 719 De Silva 5
Index: Employee Name Employee
E-Name Pointer E-No E-Name D-No
Alwis 179 Silva 7
Bandara 857 Perera 4
Costa 342 Dias 7
De Silva 719 De Silva 5
Dias 587 Alwis 4
Opatha 432 Costa 6
Peiris 197 Zoysa 2
Perera 875 Peiris 4
Silva 324 Vaas 7
Vaas 917 Bandara 3
Wickrama 785 Opatha 2
Zoysa 234 Wickrama 1
Relational Database
STORE INVENTORY STORE
Store Name | City Store Name | Part No | Quantity Store 1 | Colombo
Store 2 | Kandy
ORDERS
INVENTORY
Store Name | Part No | Vendor No | Order No | Quantity
Store 1 | P1 | 50
Store 1 | P3 | 20
PART VENDOR Store 2 | P2 | 100
Part No | Description Vendor No | Vendor Name Store 2 | P1 | 30

ORDERS PART VENDOR


Store 1 | P3 | 3428 | 0052 | 10 P1 | Printer 3428 | East West
Store 2 | P2 | 3428 | 0098 | 7 P2 | Diskette 5726 | DMS
Store 2 | P3 | 3428 | 0098 | 15 P3 | Disk Drive
Store 2 | P4 | 5726 | 0099 | 1 P4 | Modem

You might also like