Database Management Systems (DBMS)

Slides:



Advertisements
Similar presentations
BUSINESS DRIVEN TECHNOLOGY Plug-In T4 Designing Database Applications.
Advertisements

Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
Modeling & Designing the Database
Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – ER Model.
APPENDIX C DESIGNING DATABASES
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas.
Data Modeling Using the Entity-Relationship Model
Chapter 3 Relational Model Chapter 4 in Textbook.
Data Modeling Using the Entity-Relationship Model
Data Modeling Using the Entity-Relationship Model
DeSiamorewww.desiamore.com/ifm1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
CSE314 Database Systems Data Modeling Using the Entity- Relationship (ER) Model Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
Dr. Mohamed Osman Hegaz1 Conceptual data base design: The conceptual models: The Entity Relationship Model.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Information storage: Introduction of database 10/7/2004 Xiangming Mu.
Chapter 4 The Relational Model Pearson Education © 2014.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Module Title? DBMS Introduction to Database Management System.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Chapter 2 CIS Sungchul Hong
1 Introduction to Database Systems. 2 Database and Database System / A database is a shared collection of logically related data designed to meet the.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Concepts and Terminology Introduction to Database.
Databases and Database Management Systems
Chapter 3 The Relational Model. 2 Chapter 3 - Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between.
SQL Structured Query Language Programming Course.
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Copyright 2008 McGraw-Hill Ryerson 1 TECHNOLOGY PLUG-IN T5 DESIGNING DATABASE APPLICATIONS.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Database Concepts. Data :Collection of facts in raw form. Information : Organized and Processed data is information. Database : A Collection of data files.
Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Initial Design of Entity Types for the COMPANY Database Schema Based on the requirements, we can identify four initial entity types in the COMPANY database:
DeSiamorePowered by DeSiaMore1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
3 & 4 1 Chapters 3 and 4 Drawing ERDs October 16, 2006 Week 3.
Msigwaemhttp//:msigwaem.ueuo.com/1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
3 & 4 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Keys Consists of one or more attributes that determine other.
Data modeling using the entity-relationship model Chapter 3 Objectives How entities, tuples, attributes and relationships among entities are represented.
Database Environment Chapter 2. Data Independence Sometimes the way data are physically organized depends on the requirements of the application. Result:
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Exam 1 Review Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 3 Data Modeling Using Entity-Relationship Model.
Exam 1 Review Dr. Bernard Chen Ph.D. University of Central Arkansas.
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
An Introduction to Database Systems دانشگاه علم و فناوری مازندران - طراحی و ایجاد بانک های اطلاعاتی 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright (c) 2014 Pearson Education, Inc. Introduction to DBMS.
Data The fact and figures that can be recorded in system and that have some special meaning assigned to it. Eg- Data of a customer like name, telephone.
CSCI 6315 Applied Database Systems Review for Midterm Exam I Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Chapter 4 The Relational Model Pearson Education © 2009.
Department of Mathematics Computer and Information Science1 CS 351: Database Management Systems Christopher I. G. Lanclos Chapter 4.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Introduction: Databases and Database Systems Lecture # 1 June 19,2012 National University of Computer and Emerging Sciences.
Database Designsemester Slide 1 Database Design Lecture 7 Entity-relationship modeling Text , 7.1.
Data Modeling Using the Entity- Relationship (ER) Model
COP Introduction to Database Structures
Data Modeling Using the Entity- Relationship (ER) Model
Entity- Relationship (ER) Model
Chapter -3- Data Modeling Using the Entity-Relationship Model
بسم الله الرحمن الرحيم.
Translation of ER-diagram into Relational Schema
Entity Relationship Diagrams
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Presentation transcript:

Database Management Systems (DBMS) Certificate Course in Information Technology Anil Luvishewa anil@cc.ruh.ac.lk Dept of Computer Science University of Ruhuna, Sri Lanka

Learning Outcomes Understand the need for database management as opposed to the traditional stand - alone applications approach. Learn the major factors involved in proper database design including the use of entity-relationship diagrams and normalization. Learn to use SQL for data definition and data manipulation. Dept of Computer Science University of Ruhuna, Sri Lanka

Topics Introduction to DBMS The Database Architecture Database Design Process Conceptual Data modeling – (Entity-Relationship approach) The logical Database Model – (The Relational Model) Logical Database Design – (Normalization) Data Manipulation using SQL Dept of Computer Science University of Ruhuna, Sri Lanka

Introduction to Database Concepts Why use a Database? Why Database Technology? ? Dept of Computer Science University of Ruhuna, Sri Lanka

ATM users Bank ATM users Branch Branch Mobile Banking System Dept of Computer Science University of Ruhuna, Sri Lanka

Data and Information Data Information Raw facts Processed data Less meaningful Not processed Eg: Date of birth Information Processed data Meaningful Organized Eg: Processed DOB: Age Dept of Computer Science University of Ruhuna, Sri Lanka

File Processing System Individual applications maintain own private data files. Leads to data duplicate (redundancy). Inconsistency Management is very difficult Data is in different formats. Inflexible Dept of Computer Science University of Ruhuna, Sri Lanka

What is a database? A database is an organized collection of data that are related in a meaningful way and stored in a common pool which can be accessed by one or many persons for many purposes. A database is a group of related files Student database Eg: Course file Student name file Marks file File 1 File 2 File 3 Database Dept of Computer Science University of Ruhuna, Sri Lanka

What is a Database? Data collection may be . . . Electronically Collected Manually Collected Dept of Computer Science University of Ruhuna, Sri Lanka

Key Features of a database The data is input (stored) only once Organized accessible effectively and efficiently Dept of Computer Science University of Ruhuna, Sri Lanka

Database Building Blocks File/Table A collection of related records. Record A record is a group of related fields. Field Field represents an attribute, or a characteristic or a piece of information Dept of Computer Science University of Ruhuna, Sri Lanka

Database Building Blocks.. Table a Field a Record Dept of Computer Science University of Ruhuna, Sri Lanka

Database Management System (DBMS) The DBMS is a software package which allows a user to define, create, and maintain the database and provides controlled access to this database. The interface between users and data is provided by a database management system. Eg: Oracle, MS SQL-Server, MS Access MySQL, PostgreSQL Dept of Computer Science University of Ruhuna, Sri Lanka

Overview of a DBMS Admin DBMS Data-bases Users Results Modify/ Retrieval (Command) Results Admin Users Dept of Computer Science University of Ruhuna, Sri Lanka

Characteristics of Modern DBMS Query processing Transaction management Concurrency control Database recovery Database security and authorization Distributed databases Dept of Computer Science University of Ruhuna, Sri Lanka

Advantages of using DBMS Data duplication and storage space wasting can be avoided Inconsistency can be avoided Data can be shared Unauthorized access can be restricted Recovery from failures Dept of Computer Science University of Ruhuna, Sri Lanka

Disadvantages of using DBMS cost of extra hardware cost of entering data cost of training people to use DBMS cost of maintaining DBMS complex Dept of Computer Science University of Ruhuna, Sri Lanka

Components of a Database System The data in the database integrated and shared. Hardware Physically stores data, it can be secondary storage on which the database physically resides together with associated I/O devices. Software Between the physical database & the users is a layer of software which is known as the DBMS. Procedures Refer to the instructions & rules that governs the design & use of the database. Users Application Programmers. End-users Dept of Computer Science University of Ruhuna, Sri Lanka

Controlling & Maintaining a Database Database Administrator (DBA) Database Dept of Computer Science University of Ruhuna, Sri Lanka

Duties of the Database Administrator Installing and upgrades of database software Performance tuning Backup and recovery strategies Start the database & shutdown the database Monitoring the database Give and drop database access to the users Consultation with developers Dept of Computer Science University of Ruhuna, Sri Lanka

Database Architecture Data-bases Dept of Computer Science University of Ruhuna, Sri Lanka

The Need of a Database Architecture Users need to access same data but in different customized views. User views can be changed without affecting data or other user views. Users are not deal directly with physical data storage Database administrator should be able to change the database storage without affecting the user’s views. Dept of Computer Science University of Ruhuna, Sri Lanka

Database Architecture An architecture for a database system is useful for explaining the structure of a specific database system The database architecture is a three level architecture which reflects the underlying database system Dept of Computer Science University of Ruhuna, Sri Lanka

Schemas and Instances Database schema Instance The description of a database called database schema The logical structure of the database Schema is defined during the database designing and is not frequently changed Instance Data (the actual content) in the database at a particular moment in time is called database state. It is also called the instances or current set of occurrences Dept of Computer Science University of Ruhuna, Sri Lanka

Three Schema Architecture End users External Level External View 1 View n Conceptual Schema Internal DB External / Conceptual mapping Conceptual Level Conceptual / Internal mapping The goal of the three-schema architecture, is to separate the user applications and the physical database. Internal Level Dept of Computer Science University of Ruhuna, Sri Lanka

Three Schema Architecture.. Internal (Physical) Schema Defines the physical view of data (as seen by a DBMS) Describe the physical storage of the database Describe how the data is stored in the database Concern with storage space allocation, record description, data compression and encryption techniques. Dept of Computer Science University of Ruhuna, Sri Lanka

Internal (Physical) Level Struct Employee { Char Emp_no[5], Char Name[25], Date Date_joined, Boolean Pay_Tax, Int OT_Hours, Char Des_Code[3] } ; Dept of Computer Science University of Ruhuna, Sri Lanka

Three Schema Architecture.. Conceptual Schema Defines the logical view of data (as seen by programs) Describe the structure of the whole database for a community of users. Hides the details of physical storage structure. Describe entities, data types, relationships, user operations and constraints. Dept of Computer Science University of Ruhuna, Sri Lanka

Conceptual Level Employee Table Base Table Dept of Computer Science University of Ruhuna, Sri Lanka

Three Schema Architecture.. External Schema Defines the external view of data (as seen by a user) The users view of the database Describe the part of the database that a particular user group is interested. Hides the other details of the database. Dept of Computer Science University of Ruhuna, Sri Lanka

External Level Base Table (Conceptual View) The data what user wants (Only selected parts of selected records from base table) Dept of Computer Science University of Ruhuna, Sri Lanka View Table (External View)

Mapping External/Conceptual mapping Conceptual/Internal mapping Define the correspondence between a particular external view and conceptual view. This specified how a particular external schema is derived from conceptual schema Conceptual/Internal mapping Define the correspondence between the conceptual view and stored database. This specifies how the conceptual schema is represented at the internal level. If the structure of the stored database is changed, the conceptual internal mapping must also be changed accordingly. Dept of Computer Science University of Ruhuna, Sri Lanka

Staff_No FName LName DOB Batch_no Mapping.. External view 1 External view 2 Sno FName LName Staff_No LName Bno External Level Conceptual Level Staff_No FName LName DOB Batch_no Struct STAFF { int Staff_No; int Branch_No; char FName[15]; char LName[15]; date date_of_birth}; Internal (Physical) Level Dept of Computer Science University of Ruhuna, Sri Lanka

Data Independence The major objective for the three-level architecture is to provide data independence Logical Data Independence Capacity to change the conceptual schema without having to change external schemas or application program. Physical Data Independence The ability to modify the physical schema without changing the conceptual (or external ) schema Dept of Computer Science University of Ruhuna, Sri Lanka

Database Design Dept of Computer Science University of Ruhuna, Sri Lanka

Database Design The database design process can be broken down into four phases. Requirements collection and analysis phase Conceptual Design Logical Design Physical Design Dept of Computer Science University of Ruhuna, Sri Lanka

Requirements collection and analysis phase Prospective database users are interviewed to understand and document their data requirements Dept of Computer Science University of Ruhuna, Sri Lanka

Conceptual Design This is a high level description of the structure of a database Eg: E-R Diagram Concise description of the data requirements of the users and includes detailed description of the data, relationship and constraints. Dept of Computer Science University of Ruhuna, Sri Lanka

Logical Design This is the process of mapping the database structure developed in the previous phase to a particular database model. Eg: Map E-R model to relational Dept of Computer Science University of Ruhuna, Sri Lanka

Physical Design This is the process of defining structure that enables the database to be queried in an efficient manner Eg: index and hash file design Dept of Computer Science University of Ruhuna, Sri Lanka

Phases of Database Design Problem Requirements collection & analysis Database Requirements Conceptual Design Conceptual Data Model Logical Design Logical Data Model Physical Design Physical Data Model Dept of Computer Science University of Ruhuna, Sri Lanka Database Implementation

Entity – Relationship Modeling ER model is high level conceptual data model Dept of Computer Science University of Ruhuna, Sri Lanka

The Concepts of the ER Model Entity An entity is a thing in the real world with an independent existence . As entity may be an object with a physical existence . e.g. : a person , a student , a house, etc. An entity is any object that is relevant to the organization. Tangible object Intangible objects Events Dept of Computer Science University of Ruhuna, Sri Lanka

Conceptual Design Entities Department Employee Project Dependent Dept of Computer Science University of Ruhuna, Sri Lanka

The Concepts of the ER Model Attribute Each entity has particular properties or features (characteristics ) called attributes . e.g. student entity(student no, name, address, dob) Dept of Computer Science University of Ruhuna, Sri Lanka

Simple (atomic) attribute Type of attributes Simple (atomic) attribute Attributes that are not divisible are called simple or atomic attribute. Eg: Emp_No Composite attribute Can be divided in a smaller part which represent more basic attributes with independent meaning of their own. Eg: Name (First Name, Mid Name, Last Name) Dept of Computer Science University of Ruhuna, Sri Lanka

Multi-valued attribute Type of attributes Multi-valued attribute In some case an attribute can have a set of values for the same entity such attributes are called multi-valued attributes. Eg. Degree of a person , Qualification Derived attribute An attribute whose value can be calculated from related attribute values Eg: Age (Using Date of Birth) . Years Employed (Using Employed Date) . Dept of Computer Science University of Ruhuna, Sri Lanka

Relationship Relationship A meaningful association between entities. Eg: Student follows courses Employee works for department Dept of Computer Science University of Ruhuna, Sri Lanka

Relationship Degree of a Relationship Unary Relationship The degree of the relationship type is no. of participating entity types . Unary Relationship Relationship between the instances of a single entity type. E.g.: person is married to a person (1:1) Employee manages Employees (1:M) Binary Relationship Relationship between the instances of two entity types. Degree = 2; Manages Employee Student Courses follows Dept of Computer Science University of Ruhuna, Sri Lanka

Relationship Degree of a Relationship Ternary Relationship A simultaneous relationship among the instances of three entity type. Degree = 3 ,Ternary Relationship Supplier Project supplies Part Dept of Computer Science University of Ruhuna, Sri Lanka

Constraints on Relationship Types One To One ( 1: 1) .m1 .m2 .m3 . .mn .e1 .e2 .e3 .en . d1 . d2 . d3 .dn Employee entity Manages relationship Department entity EMPLOYEE DEPATMENT manages 1 1 An employee can manage one department and a department is managed by only one employee. Dept of Computer Science University of Ruhuna, Sri Lanka

Constraints on Relationship Types.. One To Many (1:N) Eg: An employee works for one department and a department has many employees. .w1 .w2 .w3 . .wn .e1 .e2 .e3 . .en . d1 . d2 . d3 .dn Employee entity Works for relationship Department entity M 1 EMPLOYEE DEPATMENT Works for Dept of Computer Science University of Ruhuna, Sri Lanka

Constraints on Relationship Types.. Many – To – Many (M:N) Eg: Consider two entities employee and the project. An employee can work on several projects and a project has many employees. .w1 .w2 .w3 . .wn .e1 .e2 .e3 .en . P1 . P2 . P3 .Pn Employee entity Works for relationship Project entity M N EMPLOYEE PROJECT Works Dept of Computer Science University of Ruhuna, Sri Lanka

Participation Constraint (Membership class) Participation constraint specifies the existence of an entity depends upon it being related to another entity through the relationship. There are two types of participation constraints. Total ( obligatory) Each and every entity in the entity set MUST BE related to the other entity set via the relationship. Partial (non–obligator, optional) Some or parts of the entity set are related to the other entity set but not necessarily all. Dept of Computer Science University of Ruhuna, Sri Lanka

Participation Constraint Examples Total participation Every employee must work for a department Works for EMPLOYEE DEPATMENT .w1 .w2 .w3 . .e1 .e2 .e3 . d1 . d2 . d3 Dept of Computer Science University of Ruhuna, Sri Lanka

Participation Constraint Examples Partial participation Some employees manage a department but not all. EMPLOYEE DEPATMENT manages .w1 .w2 . .e1 .e2 .e3 . d1 . d2 . d3 Dept of Computer Science University of Ruhuna, Sri Lanka

Attributes of relationship types Relationship types can also have attributes similar to those of entity type. Eg: Employee works on project If we need to record the number of hours per week that an employee works on project we can include an attribute hours for the works on relationship type. EMPLOYEE PROJECT Works on hours Dept of Computer Science University of Ruhuna, Sri Lanka

Weak Entity Type Weak entity Identifying Owner An entity type that is existence-dependent on some other entity type. Identifying Owner The entity type on which the weak entity type depends E.g. Employee is the Owner of Dependant. Identifying Relationship The relationship between a weak entity type and it’s owner Some entity types may not have any key attributes of their own. These are called weak entity types. Dept of Computer Science University of Ruhuna, Sri Lanka

Weak Entity Type Can not exist without it’s identifying owner Weak entity always has total participation with it’s identifying owner. A B Total Weak entity Identifying relationship Identifying owner Dept of Computer Science University of Ruhuna, Sri Lanka

Strong Entity Type Strong entity Eg: employee works on project An entity type that is not existence-dependent on some other entity type is called strong entity. Eg: employee works on project EMPLOYEE PROJECT Works on Some entity types may not have any key attributes of their own. These are called weak entity types. Dept of Computer Science University of Ruhuna, Sri Lanka

Conceptual Design – Notations Entity Type Weak Entity Relationship Identifying Relationship Dept of Computer Science University of Ruhuna, Sri Lanka

Conceptual Design – Notations Attribute Key Attribute Multi valued Attribute Derived Attribute Dept of Computer Science University of Ruhuna, Sri Lanka

Conceptual Design – Notations Composite Attribute Total Participation of E2 in R Cardinality ratio 1:N for E 1: E 2 in R E2 E1 R 1 N R E2 E 1 Dept of Computer Science University of Ruhuna, Sri Lanka

Example - A company Database A company database keeps track of a company’s employees, departments and projects. The requirements are as follows: The company is organized into departments. Each department has a unique name, a unique number and a particular employee who manages the department. A department may have several locations. Dept of Computer Science University of Ruhuna, Sri Lanka

Example - A company Database A department controls a number of projects, each of which has a unique name, a unique number and a single location Dept of Computer Science University of Ruhuna, Sri Lanka

Example - A company Database.. We store each employee’s name, i.d. number , address, salary , sex, and birth date . An employee is assigned to one department but may work on several project, which are not necessarily controlled by the same department. Employee may or may not supervise another employee and we need to keep track of the direct supervisor of each employee. Dept of Computer Science University of Ruhuna, Sri Lanka

Example - A company Database.. We want to keep track of the dependants of each employee for insurance purposes. We keep each dependant’s name , sex, birth date and relationship to the employee. Dept of Computer Science University of Ruhuna, Sri Lanka

Solution - A company Database.. Step One Identify entity types, attribute on each entity. Step Two Identify relationship types Step Three ER Diagram for the company database Dept of Computer Science University of Ruhuna, Sri Lanka

Solution - A company Database.. Step One What are the entity type in your company database? What are the attributes belongs to each entity? Sketch Dept of Computer Science University of Ruhuna, Sri Lanka

Solution - A company Database.. Step Two Identify the relationship types in your company database? Sketch Write assumptions Dept of Computer Science University of Ruhuna, Sri Lanka

Solution - A company Database.. Step Three Draw the ER Diagram. Dept of Computer Science University of Ruhuna, Sri Lanka

Solution - A company Database Detailed Conceptual Design Step One Identify entity types, attribute on each entity. Department Number Name Location DEPARTMENT Note : Name or number can be the key Dept of Computer Science University of Ruhuna, Sri Lanka

Step One - Identify entity types & attribute Project Project Number Location Name 3. Employee Name surname FN Employee Address i.d# Salary Sex Dob Number street city Dept of Computer Science University of Ruhuna, Sri Lanka

Step One - Identify entity types & attribute.. Dependent Dependent Name Dob Sex Dept of Computer Science University of Ruhuna, Sri Lanka

Step Two - Identify relationship types “A particular employee who manages the department” Assumptions: An employee can manage one department. A department is manage by only one employee. A department must have a manager at all times. (Total) 1 1 Employee Department Manages 1:1 Dept of Computer Science University of Ruhuna, Sri Lanka

Step Two - Identify relationship types.. “A department controls a number of projects.” Assumptions: A project is controlled by one department. A department controls number of projects. A project must be controlled by a department. (Total) M 1 Department Projects Controls 1:M Dept of Computer Science University of Ruhuna, Sri Lanka

Step Two - Identify relationship types.. “An employee is assigned to one department but many worked on several project.” Assumptions: A department has many employee. An employee must belong to a department and department must have employees. (Total) A project may have employees An employee can work on a project and a project should have employee (Total) 1 M Assigned to Employee Department N M Works on Project M:1 Dept of Computer Science University of Ruhuna, Sri Lanka

Step Two - Identify relationship types.. “An employee may have dependents.” Has dependant 1 M Employee Dependent Dept of Computer Science University of Ruhuna, Sri Lanka

Step Two - Identify relationship types.. “An employee may or may not supervise another employee.” Assumptions: Supervision relationship is known as recursive relationship. Employee play two roles: Supervisor , Supervisee Employee 1 M supervisor supervisee supervision Dept of Computer Science University of Ruhuna, Sri Lanka

E-R Model (schema) Diagram for the company database Assigned to EMPLOYEE N 1 DEPARTMENT 1 1 1 1 Manages N Controls Supervision 1 N Has dependant M Attributes of Relationship types Star – date - in manages relationship Hours – in work – on relationship Works on N Project N DEPARTMENT Dept of Computer Science University of Ruhuna, Sri Lanka

THE RELATIONAL DATA MODEL Dept of Computer Science University of Ruhuna, Sri Lanka

Introduction This model was introduced by Ted Codd of IBM in the early 1970’s. Provide concepts which can be used to build a logical design. It is based on the concept of mathematical relations. DBMS which supports this model is said to be a Relational Database Management System (RDBMS) The RDB is a collection of relations. Dept of Computer Science University of Ruhuna, Sri Lanka

Terminology Relation Attribute Tuple A relation is a table with columns and rows. Attribute An attribute is a named column of a relation. Tuple A tuple is a row of a relation. Dept of Computer Science University of Ruhuna, Sri Lanka

Terminology.. Degree Relation schema The number of attributes of a relation. Relation schema A relation name followed by set of attributes A relation schema is denoted by R (A1, A2, A3,….,An) R – Relation name A1, A2, A3,….,An - – list of attributes Dept of Computer Science University of Ruhuna, Sri Lanka

Terminology.. Cardinality The cardinality of the relation is the number of tuples present in the body, which varies with time. Dept of Computer Science University of Ruhuna, Sri Lanka

Example - Terminology St – No Name Address Dob S 1 Kamal Matara Attribute STUDENT St – No Name Address Dob S 1 Kamal Matara 01-05-1980 S 2 Himali Kaluthara 31-10-1981 S 3 Renuka Galle 19-06-1979 Tuple R (Student) Degree of student – 4 Cardinality of student -3 Dept of Computer Science University of Ruhuna, Sri Lanka

Properties of Relation The relation has a name that is distinct from all other relations Tuple of relation do not have any particular order. Each attribute has a distinct name Attributes are unordered. There are no duplicate tuple. All attribute values are atomic. i.e. Not divisible into components. Dept of Computer Science University of Ruhuna, Sri Lanka

Key Types of a Relation Candidate key A candidate key is an attribute or set of attributes whose values uniquely identify a tuple of a relation. There may be more than one candidate keys for a relation. E.g. Consider the following relation schema Department (d#, dname, location ) Assumption : d# and dname are unique Candidate keys:{d#} and {dname} Dept of Computer Science University of Ruhuna, Sri Lanka

Key Types of a Relation.. Primary key One of the relation candidate key is selected as primary key. The other candidate keys are called alternate keys. E.g.Consider the following relation schema Department (d#, dname, location ) Assumption : d# and dname are unique Primary key: d# Alternate key: dname Dept of Computer Science University of Ruhuna, Sri Lanka

Key Types of a Relation.. Foreign key A foreign key is an attribute in one relation that matches the primary key attribute of another relation. E.g.Consider the following relation schemas Department (d#, dname, location ) Project (P#, desc, d#, Start_date) Foreign key: d# is foreign key in Project schema Dept of Computer Science University of Ruhuna, Sri Lanka

Eg: Foreign key... Department PK Project PK FK Dept_No Dept_Name Phone Construction 0415670045 D02 Finance 0412222652 D03 Personal PK Prj_No Prj_Name Location Dept P01 ABC Auditing Matara D02 P02 TRC Budgeting Colombo P03 Ground Construction Galle D01 Project PK FK Dept of Computer Science University of Ruhuna, Sri Lanka