You are on page 1of 38

HND Computing

UNIT 38: Database Management


Systems

Faisal saghir
Relational Model
Object Relational Model
Object Based data Model
Brief Histor y of the Relational Model

2
 “A DBMS that manages data as collection of tables
in which all data relationships are represented by
common values in related tables.”

 “A DBMS that follows all the twelve rules of CODD


is called RDBMS”

3
Relational Database definition

All information must be represented explicitly in


one and only one way: as values in tables and
each & every datum in the database must be
accessible by specifying a table name, a column
name, and a primary key.

4
PRINCIPLES OF RELATIONAL MODEL
Data about various entities and their relationships
are stored in a series of logical tables (also known as
relations).

A relation is a two-dimensional table with certain imposed


restrictions:

1. Each Row is unique: No duplicate row


2. Entries in any column have the same domain.
3. Each column has a unique name
4. Order of the columns or rows is irrelevant
5. Each entry in the table is single valued:
No group item, repeating group, or array is allowed.

Note: A domain is the set of all possible values an attribute may assume.
Example: Domain of Major= (Acct, Mktg, Mgmt, ISOM, Fina)
5
 Relational database: a set of relations.
Relation: made up of 2 parts:
– Schema : specifies name of relation,
plus name and type of each column.
• E.g. Students(sid: string, name: string, login: string,
age: integer, gpa: real)
– Instance : a table, with rows and columns.
•#rows = cardinality
•#fields = degree / arity
• Can think of a relation as a set of rows or tuples.
– i.e., all rows are distinct

6
 The Relational Model developed by Dr. E. F. Codd at IBM
in the late 1960s
 The model built on mathematical concepts, which
expounded in the famous work called "A Relational
Model of Data for Large Shared Databanks".
 At the core of the relational model is the concept of a
table (also called a relation) in which all data is stored.
 Records (horizontal rows also known as tuples) &
Fields (ver tical columns also known as attributes).
 It is important to note that how or where the tables of data
are stored makes no difference.
 Table can be identified by a unique name.
 This is quite a bit different from the Hierarchical & Network
models in which the user had to have an understanding
of how the data was structured within the
database in order to retrieve, inser t, update, or
delete records from the database. 7
Advantages:
 The data access methodology in relational
model is quite different from and better than the
earlier database models .
 Another benefit of the relational system is that it
provides extremely useful tools for database
administration.
 Meta-data (data about the table and field names
which form the database structure, access rights to
the database, integrity and data validation
rules etc).
 Thus everything within the relational model can be
stored in tables. This means that many relational
systems can use operations recursively in order
to provide information about the database.

8
TABLE (Relation) Domain Domain
Primary
Supplier Key
a SName Quantity City

S1 Keyur 20 Ahmedabad

S2 Vinay 10 Surat
Tuples Cardin
S3 Chirag 40 Baroda ality
S4 kevin 34 Rajkot

S5 Nayan 25 Bhavnagar

Attributes
Degree 9
Attribute (field):
Member of a relation type (set / table).
Attribute Name:
All attribute names must be unique within a
table / relation.
Attribute Domain:
A set of all possible values that can be attain by
an attribute.
Attribute Value Set:
Values currently contained in an attribute.
Relation / Table Degree:
Number of attributes in a relation / table.
Tuples: Rows in a table / relation.
Cardinality: Number of tuples in a relation / table.
10
Student(studno,name,address)
Schema
Course(courseno,lecturer)

Student(123,Bloggs,Woolton) Instance
(321,Jones,Owens)
sid Name Login age GPA

53666 Jones Jones@ca 18 3.4


53444 smith Smith@ecs 18 3.2
53777 Blake Blake@aa 19 3.8

• Cardinality = 3, arity = 5 , all rows distinct

•Do all values in each column of a relation


instance have to be distinct?
11
Database Schema
The description of the database is called
database schema. A database schema is
describe during database design and not
expected to change frequently.

Schema Diagram
Displayed schema is called schema diagram.
Each object in schema is called a schema
construct.
12
Database instance (occurrence or state)
The data in a database at a particular
moment of time.

Intension & Extension


The schema is sometimes called the
intension and a database instance is called
an extension of the schema.

13
Table

Field
CD_ID Title Artist Genre
1 The Wall Pink Floyd Rock

Record 2 Blue Train John Coltrane Jazz


3 Requiem W.A. Mozart Classical

14
15
Tuple:

 The actual data values for the attributes of a relation


are stored in tuples, or rows, of the table.
 It is not necessary for a relation to have rows in order
to be a relation; even if no data exists for the relation
 The relation remains defined with its set of attributes
Attribute:
 The term attribute refers to characteristics.This
simply means that what the column contains will be
defined by the attribute of the column

16
EXAMPLES OF ATTRIBUTE
DOMAINS

17
18
• How and where the tables of data stored make
no difference You can access child table with out
accessing parent table. Non-navigational in
nature
• Find the data on the basis of the data values
themselves.
• One point data
administration Controlling
redundancy
• Data abstraction
• Provide security
• Data entry , update and deletion will be
efficient.
• Changes to the of the database is
somewhat self- documenting. 19
DBMS RDBMS
The concepts of relationships is It is based on the concept
missing in a DBMS. If it exits it is Of relationships
very less.

Speed of operation is very slow Speed of operation is very Fast


Hardware and Software requirements Hardware and Software
are minimum
requirements are High
Platform used is normally DOS Platform used can be any DOS,
UNIX,VAX,VMS, etc
Uses concept of a file Uses concept of table

DBMS normally use 3GL RDBMS normally use a 4GL


Examples are dBase, FOXBASE, etc Examples are ORACLE, INGRESS,
SQL Server 2000 etc
20
  Oracle
  Sybase
  Microsoft SQL Server
  Informix
  Ingress
  DB2

21
EXAMPES

Country Capital Country Currency


Italy Rome Italy Lira
India New Delhi India Rupee
China Beijing China Quan
France Tokyo France Yen
Japan Paris Japan Francs

22
Car

Engine Body Chassis

Left Door Right Door Hood Roof

Handle Window Lock

23
Lecture No-2

• Relational Database
Relational Database
● Relational Database Management System (RDBMS)
consists of:
– A set of tables
– A schema
● A schema:
– is a description of data in terms of data model
– Defines tables and their attributes (field or
● column)
– Can be thought as records
– eg. information on student is stored in a relation
with the following schema:
Student(sid: string, sname: string, login: string, 10
gpa: numeric)
Relational Database
● Tables ≡ relation:
– is a subset of the Cartesian product of the domains of the column
data type.
– Stores information about an entity or theme
– Consist of columns (fields) and rows (records).
– Rows ≡ tuple, describing information about a single item, eg. A
specific student
– columns ≡ attributes, describing a single characteristic
(attributes) of its item, eg. Its ID number, GPA, etc
– Every row is unique & identified by a key
● Entity is
– an object in the real world that is distinguishable from other
objects. eg. Students, lecturers, courses, rooms.
– Described using a set of attributes whose domain values must be
identified.
11
● The attribute 'name of Student' ⇨20-character strings
Creating Relational Database
● How to create relational database?
– Need RDBMS (MySQL, Oracle, etc)
– Just take MySQL as an open source RDBM
● With user Inteface
– eg. phpMyAdmin →providing graphical user interface
– Free to use any scripts or programming languages
● Using SQL commands in terminal
● Using SQL integrated in your code

12
Creating Relational Database
● How to create relational database in GUI?
– Step 1: install XAMPP (just an example)
a cross-platform Apache HTTP Server,
MySQL Server & interpreters for script
– Step 2: start your XAMPP first:
/xampp_or_lampp_path start
eg. /opt/lampp/lampp start
– Open your browser, and
type: localhost/phpmyadmin

13
RDBMS Example
● Database Server: MySQL 5.5.27
● Web Server: Apache through XAMPP
Package

1
4
RDBMS Example

● Creating table, defining attributes & their


domains

1
5
RDBMS Example
● Creating table, defining attributes & their
domains

1
6
RDBMS Example
● Each relation is defined to be a set of unique
tuples of rows

Fields (Attributes, Columns)

Tuples
(Recods
, row)

1
7
Key Constraints
● Key constraint is a statement that a certain
minimal subset of the relation is a unique
identifier for a tuple.
● Two Types of keys:
– Primary key:
– Foreign key
● Primary key:
– a unique identifier for a tuple
(row)
● Sid is a primary key for

● student, Cid is a primary key


– for Course
Primary key fields are
indexed 18
Key Constraints
● Foreign key:
– A kind of a logical pointer
– a key to refer to relation with other tables &
should match the primary key of the referenced

relation
Foreign key fields are also often indexed if they
are important for retrieval.
courses(Cid, Cname, Instructor, Semester
) Student(Sid, Sname, login, GPA)
How do you express which students take which
course?
19
Key Constraints
● Need a new table
:–
enrolled(Cid, grade, Sid)
– Sid/Cid in enrolled are foreign keys refering to Sid
in Student table & Cid in Courses.

Courses Enrolled Student

2
0
Relations
● One to one :
– Each primary key relates only one record
in related table
● One to many:
– The primary key relates to one or many records
in related table

● Many to Many:
– The primary key relates to many records in
related table, and a record in related table can
relate to many primary keys on another table
21
Storing Relationships using Keys
● Modeling data is one thing, storing it in a database
is another one.
● In relational database, the 'rules' are:
– If the relationship to be stored is 1:N, place the
attribute identified as the primary key from the one
table as a foreign key in another table.
– If the relationship to be stored is M:N, a new table
structure must be created to hold the association.
This 'bridge' table will have as foreign key attributes,
the primary key of each table that is part of
relationship
● The key for the 'bridge' table then becomes either:
– The combination of all the foreign keys OR
22
– A new attribute will be added as a surrogate key
Storing Relationships using Keys

2
3

You might also like