Sei sulla pagina 1di 75

Education and Research

We enable you to leverage knowledge anytime, anywhere!

RDBMS- Core Day1

Ver. No.:4.0 ER/CORP/CRS/DB92 Ver. No.: 0.1 Confidential Copyright 2008, Infosys Technologies Ltd.

General Guideline
(2008) Infosys Technologies Ltd. This document contains valuable confidential and proprietary information of Infosys. Such confidential and proprietary information includes, amongst others, proprietary intellectual property which can be legally protected and commercialized. Such information is furnished herein for training purposes only. Except with the express prior written permission of Infosys, this document and the information contained herein may not be published, disclosed, or used for any other purpose.

Copyright 2008, Infosys Technologies Ltd.

Confidential

Confidential Information
This Document is confidential to Infosys Technologies Limited. This document contains information and data that Infosys considers confidential and proprietary (Confidential Information). Confidential Information includes, but is not limited to, the following:
Corporate and Infrastructure information about Infosys Infosys project management and quality processes Project experiences provided included as illustrative case studies

Any disclosure of Confidential Information to, or use of it by a third party, will be damaging to Infosys. Ownership of all Infosys Confidential Information, no matter in what media it resides, remains with Infosys. Confidential information in this document shall not be disclosed, duplicated or used in whole or in part for any purpose other than reading without specific written permission of an authorized representative of Infosys. This document also contains third party confidential and proprietary information. Such third party information has been included by Infosys after receiving due written permissions and authorizations from the party/ies. Such third party confidential and proprietary information shall not be disclosed, duplicated or used in whole or in part for any purpose other than reading without specific written permission of an authorized representative of Infosys.
Copyright 2008, Infosys Technologies Ltd.

Confidential

Learning approach
The following are strongly suggested for a better learning and understanding of this course: Noting down the key concepts in the class, explained by the educator Analyze all the examples / code snippets provided Study and understand the self study topics Completion and submission of all the assignments, on time Completion of the self review questions in the lab guide Study and understand all the artifacts including the reference materials / e-learning / supplementary materials specified Completion of the project (if applicable for this course) on time inclusive of individual and group activities Taking part in the self assessment activities Participation in the doubt clearing sessions
Copyright 2008, Infosys Technologies Ltd.

Confidential

C Map- RDBMS Core

Copyright 2008, Infosys Technologies Ltd.

Confidential

Course Objectives
Introduction of basic RDBMS concepts Familiarization with SQL

Commands of DDL,DML and DCL Languages


Concept of Joins

Concept of Sub Queries


Views

Copyright 2008, Infosys Technologies Ltd.

Confidential

Session Plan
Day1 Traditional Approach, Why DBMS ? Users of DBMS Data Models RDBMS, Keys ER Modeling ERD Case Studies Day2 Transforming an ER model to Relational Schema Functional Dependencies Normalization Day3
Introduction to SQL and SQL Plus

Day 4 Day 5 Day 6

Aggregate Functions Group By and Having clause Joins Independent Sub Queries Correlated Sub queries Use of EXISTS and NOT EXISTS

Views DCL

DDL DML (Till Order By)

Copyright 2008, Infosys Technologies Ltd.

Confidential

References
Henry F Korth, Abraham Silberschatz, Database system concepts, McGraw-Hill International editions, Computer Science Series(1991), Second ed., Elmasri, Navathe, "Fundamentals of Database Systems", Addison Wesley, Third ed

C.J.Date, "An introduction to Database Systems", Narosa Publications, Sixth ed.,

Copyright 2008, Infosys Technologies Ltd.

Confidential

Session Plan Day1


Traditional File Approach Advantages of a DBMS Three layers of abstraction Users of DBMS Database Models Types of Databases Relational Model Basics Keys Conceptual Design ER Modelling ER Modelling Notations ERD Case study Merits & Demerits of ER Modeling

Copyright 2008, Infosys Technologies Ltd.

Confidential

Traditional Method of Data Storage

Loan_Processing (Application Program)

Fixed_Deposit_Processing (Application Program)

Transaction_Processing (Application Program)

File System

Customer_Details.dat

Customer_Loan.dat

Customer_Fixed_Deposit.dat

Customer_Transaction.dat

Copyright 2008, Infosys Technologies Ltd.

10

Confidential

Problems: Traditional Approach


Data Security Data Redundancy

Data Isolation
Program / Data Dependence Lack of Flexibility Concurrent Access Anomalies

Copyright 2008, Infosys Technologies Ltd.

11

Confidential

Database Management System


DBMS is consist of collection of interrelated files and set of programs.

These set of programs allow users to access and modify files


Primary Goal is to provide a convenient and efficient way to store, retrieve and modify information Layer of abstraction between the application programs and the file system

Copyright 2008, Infosys Technologies Ltd.

12

Confidential

Where does the DBMS fit in?


Loan_Processing (Application Program) Fixed_Deposit_Processing (Application Program) Transaction_Processing (Application Program)

DBMS

File System

Customer_Loan Customer_Details Customer_Transaction Customer_Fixed_Deposit

Bank Database

Copyright 2008, Infosys Technologies Ltd.

13

Confidential

Difference Between File and DBMS Operations


File system Interface End User Application Programs DBMS Interface End User Application Programs Interface through Query (SQL) Interface through high level language
SELECT * FROM Customer_Details READ CUSTOMER_DETAILS-FILE AT END STOP RUN

DBMS

Operating System (Disk Manager, File Manager)

Operating System (Disk Manager, File Manager)

Customer_Details file Customer_Loan file File System (Disk Storage)

Customer_Details table Customer_Loan table Database(Disk Storage)

Copyright 2008, Infosys Technologies Ltd.

14

Confidential

Three-layer Architecture
External / View Level
(Individual User View)

External Schema A

External Schema B

External Schema C

Conceptual View (Common User View)

Conceptual Schema

Internal Level (Storage View)

Internal Schema

Copyright 2008, Infosys Technologies Ltd.

15

Confidential

Detailed System Architecture


Mike (User) Graham (User) Jack (User) Justin (User)

External Schemas

External View A

External View B

Schemas & mappings built & maintained by the DBA

External / conceptual mapping

DBMS

Conceptual Schema

Conceptual view

Conceptual / Internal mapping Database Administrator (DBA)

Storage structure definition (Internal Schema)

Database ( Internal view)


Copyright 2008, Infosys Technologies Ltd.

16

Confidential

An example of the three levels


Customer_Loan Cust_ID : 101 Loan_No : 1011 Amount_in_Dollars : 8755.00 CREATE TABLE Customer_Loan ( Cust_ID NUMBER(4) Loan_No NUMBER(4) Amount_in_Dollars NUMBER(7,2))

External

Conceptual

Cust_ID Loan_No Amount_in_Dollars

TYPE = BYTE (4), OFFSET = 0 TYPE = BYTE (4), OFFSET = 4 TYPE = BYTE (7), OFFSET = 8

Internal

Copyright 2008, Infosys Technologies Ltd.

17

Confidential

Users of a DBMS
Database Administrator (DBA) Managing information contents Liaison with users Enforcing security and integrity rules Strategizing backup & recovery Monitoring performance Database designers Application programmers End users

Copyright 2008, Infosys Technologies Ltd.

18

Confidential

Advantages of a DBMS
Data independence Reduction in data redundancy Better security Better flexibility Effective data sharing

Enforces integrity constraints


Enables backup and recovery

Copyright 2008, Infosys Technologies Ltd.

19

Confidential

Data Models
Definition of data model : A conceptual tool used to describe : Data Data relationships

Data semantics
Consistency constraints

Copyright 2008, Infosys Technologies Ltd.

20

Confidential

Types of data models


Object based logical model Entity relationship model

Record based logical model Hierarchical data model Network data model Relational data model

Copyright 2008, Infosys Technologies Ltd.

21

Confidential

Record based data model Hierarchical data model


ROOT

101 Smith A. Mike 1020 Savings Downtown

Smith_Mike@yahoo.com

102 Smith S. Graham 2348 Checking Bridgewater Smith_Graham@rediffmail.com

1011 8755.00 1011 8755.00 103 Langer G. Justin 3421 Savings Plainsboro Langer_Justin@yahoo.com

2010 2555.00

2015 2000.00

E.g.: Information Management System (IMS) from IBM


Copyright 2008, Infosys Technologies Ltd.

22

Confidential

Record based data model Network data model


101 Smith A. Mike 1020 Savings Downtown Smith_Mike@yahoo.com 1011 8755.00

102 Smith S. Graham 2348 Checking Bridgewater Smith_Graham@rediffmail.com 2010 2555.00 103 Langer G. Justin 3421 Savings Plainsboro Langer_Justin@yahoo.com 2015 2000.00 104 Quails D. Jack 2367 Checking Downtown Quails_Jack@yahoo.com Jones_Simon@rediffmail.com 2056 3050.00

105 Jones E. Simon 2389 Checking Brighton

E.g.: Integrated Data Management System(IDMS) from Honeywell


Copyright 2008, Infosys Technologies Ltd.

23

Confidential

Record based data model Relational data model

Copyright 2008, Infosys Technologies Ltd.

24

Confidential

Relational model basics


Data is viewed as existing in two dimensional tables known as relations A relation (table) consists of unique attributes (columns) and tuples (rows) Sometimes the value to be inserted into a particular cell may be unknown, or it may have no value. This is represented by a NULL Null is not the same as zero, blank or an empty string Relational Database: Any database whose logical organization is based on relational data model. RDBMS: A DBMS that manages the relational database.

Copyright 2008, Infosys Technologies Ltd.

25

Confidential

Keys in relational model


Candidate key A Candidate key is a set of one or more attributes(minimal) that can uniquely identify a row in a given table.

Primary Key During the creation of the table, the Database Designer chooses one of the Candidate Key from amongst the several available, to uniquely identify row in the given table.
Alternate Key
The candidate key that is chosen to perform the identification task is called the primary key and the remaining candidate keys are known as alternate keys. No of Alternate Keys = No of Candidate Keys - 1

Copyright 2008, Infosys Technologies Ltd.

26

Confidential

Key and Non-key Attributes in Relational Model


Key Attributes
The attributes that participate in the Candidate key are Key attributes

Non-Key Attributes The attributes other than the Candidate Key attributes in a table/relation are called Non-Key attributes. OR The attributes which do not participate in the Candidate key.

Copyright 2008, Infosys Technologies Ltd.

27

Confidential

Example
Given a relation Trainee(Empno, FirstName, LastName, Email, PhoneNo) Assumptions: i. Empno for each trainee is different. ii. Email for each trainee is different iii. PhoneNo for each trainee is different iv. Combination of FirstName and LastName for each trainee is different Candidate key: {Empno},{Email},{PhoneNo},{FirstName,LastName} Primary key: {Empno}

Alternate Key: {Email},{PhoneNo},{FirstName,LastName}

Copyright 2008, Infosys Technologies Ltd.

28

Confidential

Exercise on Key attributes


Given a relation R1(X,Y,Z,L) and the following attribute(s) can uniquely identify the records of relation R1. 1)X 2)X,L 3)Z,L Identify the following in relation R1? Candidate Key(s) Primary Key Alternate Key Key attribute(s) Non-key attribute(s)

Copyright 2008, Infosys Technologies Ltd.

29

Confidential

What are the candidate keys?


Case 1 Assumptions One customer can have only one account An account can belong to only one customer
while deciding the Candidate key do not get misguided by the data present in the table.

Cust_ID Cust_Last_ Cust_Mid Cust_First Account Account_ Bank_Branch Name _Name _Name _No Type 101Smith A. Mike 1020Savings Downtown 102Smith S. Graham 2348Checking Bridgewater 103Langer G. Justin 3421Savings Plainsboro 104Quails D. Jack 2367Checking Downtown 105Jones E. Simon 2389Checking Brighton Customer_Detail records from Customer_Details table

Cust_Email Smith_Mike@yahoo.com Smith_Graham@rediffmail.com Langer_Justin@yahoo.com Quails_Jack@yahoo.com Jones_Simon@rediffmail.com

Copyright 2008, Infosys Technologies Ltd.

30

Confidential

What are the candidate keys?


Case 2 Assumptions One customer can have many accounts An account can belong to only one customer

Cust_ID Cust_Last_ Cust_Mid Cust_First Account Account_ Bank_Branch Name _Name _Name _No Type 101Smith A. Mike 1020Savings Downtown 102Smith S. Graham 2348Checking Bridgewater 103Langer G. Justin 3421Savings Plainsboro 104Quails D. Jack 2367Checking Downtown 105Jones E. Simon 2389Checking Brighton Customer_Detail records from Customer_Details table

Cust_Email Smith_Mike@yahoo.com Smith_Graham@rediffmail.com Langer_Justin@yahoo.com Quails_Jack@yahoo.com Jones_Simon@rediffmail.com

Copyright 2008, Infosys Technologies Ltd.

31

Confidential

What are the candidate keys?


Case 3 : Assumptions One customer can have many accounts. An account can belong to more than one customer (joint account)

Cust_ID Cust_Last_ Cust_Mid Cust_First Account Account_ Bank_Branch Name _Name _Name _No Type 101Smith A. Mike 1020Savings Downtown 102Smith S. Graham 2348Checking Bridgewater 103Langer G. Justin 3421Savings Plainsboro 104Quails D. Jack 2367Checking Downtown 105Jones E. Simon 2389Checking Brighton Customer_Detail records from Customer_Details table

Cust_Email Smith_Mike@yahoo.com Smith_Graham@rediffmail.com Langer_Justin@yahoo.com Quails_Jack@yahoo.com Jones_Simon@rediffmail.com

Copyright 2008, Infosys Technologies Ltd.

32

Confidential

Choosing a Primary key from Candidate keys -Guidelines

Give preference to numeric column(s) Give preference to single attribute Give preference to minimal composite key
Primary Key of the table, Customer_Details

Cust_ID Cust_Last_ Cust_Mid Cust_First Account Account_ Bank_Branch Name _Name _Name _No Type 101Smith A. Mike 1020Savings Downtown 102Smith S. Graham 2348Checking Bridgewater 103Langer G. Justin 3421Savings Plainsboro 104Quails D. Jack 2367Checking Downtown 105Jones E. Simon 2389Checking Brighton Customer_Detail records from Customer_Details table

Cust_Email Smith_Mike@yahoo.com Smith_Graham@rediffmail.com Langer_Justin@yahoo.com Quails_Jack@yahoo.com Jones_Simon@rediffmail.com

Copyright 2008, Infosys Technologies Ltd.

33

Confidential

Foreign Key
Foreign key
A Foreign Key is a set of attribute (s) whose values are required to match values of a column in the same or another table.
DEPT (Parent /Master/Referenced Table) EMP (Child /Referencing Table)

DeptNo

DName

EmpNo 1001 1002 1003 1004

EName Elsa John Maria Maida

EDeptNo D1 D2 Null D1

D1
D2

IVS
ENR

Points to remember

Foreign key values do not (usually) have to be unique. Foreign keys can also be null . To enter the data in child table corresponding data must be present in master table or NULL is the default entry in child table in the referenced column ( FK column)

Copyright 2008, Infosys Technologies Ltd.

34

Confidential

Foreign Key
Foreign key

Points to remember
A Foreign Key is a set of attributes of a table, whose values are required to match values of some Candidate Key in the same or another table Foreign Key column must match the values of the corresponding Candidate Key column. This is known as Referential constraint. A table which has a Foreign Key referring to its own Candidate Key is known as Self-Referencing table

Copyright 2008, Infosys Technologies Ltd.

35

Confidential

Education and Research


We enable you to leverage knowledge anytime, anywhere!

DATABASE DESIGN TECHNIQUE

Copyright 2008, Infosys Technologies Ltd.

36

Confidential

Database Design Techniques


Top down Approach
In Top down approach we start defining the data set and then we go on defining data elements in those sets. This approach generally leads to redundant information in one or more table. Some references call this Entity - Relationship modeling.

Bottom Up approach
In Bottom up approach we start defining required attribute first and then group these attribute to form the entities. Another term used for this method is normalization from functional dependencies.

Copyright 2008, Infosys Technologies Ltd.

37

Confidential

Education and Research


We enable you to leverage knowledge anytime, anywhere!

ER MODELING -TOP DOWN APPROACH

Copyright 2008, Infosys Technologies Ltd.

38

Confidential

ER modeling
ER modeling: A graphical technique for understanding and organizing the
data independent of the actual database implementation.

Entity: Any thing that may have an independent existence and about which
we intend to collect data. also known as Entity type. e.g.: Trainee Relationships: Associations between entities. e.g.: Trainee belongs to a Batch Attributes: Properties/characteristics that describe entities. e.g.: Trainee Name, BatchName, DOB, Address, etc.

Copyright 2008, Infosys Technologies Ltd.

39

Confidential

Entity Types
Regular Entity: Entity that has its own key attribute (s).
e.g.: Employee, student ,customer, policy holder etc.

Weak entity: Entity that depends on other entity for its existence and
doesnt have key attribute (s) of its own e.g. : spouse of employee

Copyright 2008, Infosys Technologies Ltd.

40

Confidential

Attributes
The set of possible values for an attribute is called the domain of the attribute e.g.: 1. The domain of attribute marital status is having four values: single, married, divorced or widowed. 2. The domain of the attribute month is having twelve values ranging from January to December. Key attribute: The attribute (or combination of attributes) that is unique for every entity instance e.g.: the account number of an account, the employee id of an employee etc.

Copyright 2008, Infosys Technologies Ltd.

41

Confidential

Attributes Types
Types of Attributes Simple attribute Composite attribute Single valued Multi-valued Stored Attribute Derived Attribute Definition Cannot be divided into simpler components Can be split into components Can take on only a single value for each entity instance Can take up many values Attribute that need to be stored permanently Attribute that can be calculated based on other attributes. Example Gender of the employee Address of the employee Age of the employee Skill set of the employee Date of joining of the employee Years of service of the employee

Copyright 2008, Infosys Technologies Ltd.

42

Confidential

Degree of a Relationship
Degree: the number of entity types involved One Unary Two Binary Three Ternary

e.g.:
1. employee manager-of employee is unary 2. employee works-for department is binary 3. Customer purchases items from a shop keeper Here customer purchase item, shop keeper is a ternary relationship
Copyright 2008, Infosys Technologies Ltd.

43

Confidential

Cardinality
Relationships can have different connectivity one-to-one (1:1) one-to-many (1:N) many-to-one (M:1) many-to-many (M:N) e.g.: Employee head-of department (1:1) Lecturer offers course (1:N) assuming a course is taught by a single lecturer Student enrolls course (M:N)

Copyright 2008, Infosys Technologies Ltd.

44

Confidential

Relationship Participation
Total : Every entity instance must be connected through the relationship to
another instance of the other participating entity types

Partial: All instances need not participate

e.g.: Employee Head-of Department Employee: partial Department: total

Copyright 2008, Infosys Technologies Ltd.

45

Confidential

Education and Research


We enable you to leverage knowledge anytime, anywhere!

ER MODELING - NOTATIONS

Copyright 2008, Infosys Technologies Ltd.

Confidential

ER Modeling -Notations
An Entity can be defined as an object or concept about which user wants to store information. A weak Entity requires another Entity for its existence. Example Order Item depends upon Order Number for its existence. Without Order Number it is impossible to identify Order Item uniquely. Properties or characteristics of an Entity is called Attributes of entity If an attribute is the unique or distinguishing characteristic of the Entity it is called Key Attribute If an attribute can have more than one value then it is called multi-valued attribute. For example, an employee Entity can have multiple skill values.
Copyright 2008, Infosys Technologies Ltd.

47

Confidential

ER Modeling -Notations
If the value of an attribute can be derived from another attribute it is called derived attribute. For example, an employee's monthly salary is based on the employee's basic salary and House rent allowance. Relationships in ER Diagram illustrate how two entities of database share information.

We connect a weak entity through a strong entity using a weak relationship notation.

Copyright 2008, Infosys Technologies Ltd.

48

Confidential

ER Modeling -Notations
Customer

Cardinality of relationship tells how many instances of an Entity type is relate to one instance of another Entity Type. M,N both represent MANY and 1 represents ONE Cardinality

N
1 Account M Transaction

An entity can be self linked. For example, employees can supervise other employees

Copyright 2008, Infosys Technologies Ltd.

49

Confidential

Composite attribute
floor building

DOB Name Address

E#

Employee

Designation

Copyright 2008, Infosys Technologies Ltd.

50

Confidential

Unary Relationship

Employee

Manages

Copyright 2008, Infosys Technologies Ltd.

51

Confidential

Role names
Role names may be added to make the meaning more explicit
subordinate

Employee
1
Manager

Manages

Copyright 2008, Infosys Technologies Ltd.

52

Confidential

Binary Relationship

Employee

Works for

Department

Copyright 2008, Infosys Technologies Ltd.

53

Confidential

Ternary Relationship

Medicine

Doctor

Prescription

Patient

Copyright 2008, Infosys Technologies Ltd.

54

Confidential

Relationship participation

Employee

head of

department

Copyright 2008, Infosys Technologies Ltd.

55

Confidential

Attributes of a Relationship
Medicine

Number of days dosage

Doctor

Prescription

Patient

Copyright 2008, Infosys Technologies Ltd.

56

Confidential

Weak entity
Id ---1 N

E#

name

Employee

has

dependant

The dependant entity is represented by a double lined rectangle and the identifying relationship by a double lined diamond

Copyright 2008, Infosys Technologies Ltd.

57

Confidential

Case Study ER Model For a college DB


Assumptions : A college contains many departments Each department can offer any number of courses Many instructors can work in a department An instructor can work only in one department For each department there is a Head An instructor can be head of only one department Each instructor can take any number of courses A course can be taken by only one instructor A student can enroll for any number of courses Each course can have any number of students

Copyright 2008, Infosys Technologies Ltd.

58

Confidential

Steps in ER Modeling
Identify the Entities Find relationships Identify the key attributes for every Entity Identify other relevant attributes Draw complete E-R diagram with all attributes including Primary Key Review your results with your Business users

Copyright 2008, Infosys Technologies Ltd.

59

Confidential

Steps in ER Modeling
Step 1: Identify the Entities
DEPARTMENT

STUDENT
COURSE INSTRUCTOR

Copyright 2008, Infosys Technologies Ltd.

60

Confidential

Steps in ER Modeling
Step 2: Find the relationships
One course is enrolled by multiple students and one student enrolls for multiple courses, hence the cardinality between course and student is Many to Many.
COURSE

ENROLLED BY

STUDENT

The department offers many courses and each course belongs to only one department, hence the cardinality between department and course is One to Many.
DEPARTMENT OFFERS COURSE

One department has multiple instructors and one instructor belongs to one and only one department , hence the cardinality between department and instructor is one to Many.
DEPARTMENT

HAS

INSTRUCTOR

Copyright 2008, Infosys Technologies Ltd.

61

Confidential

Steps in ER Modeling
Step 2: Find the relationships(Cont..)

Each department there is a Head of department and one instructor is Head of department ,hence the cardinality is one to one .
DEPARTMENT

HEADED BY

INSTRUCTOR

One course is taught by only one instructor, but the instructor teaches many courses, hence the cardinality between course and instructor is many to one.
M OFFERS 1

COURSE

INSTRUCTOR

Copyright 2008, Infosys Technologies Ltd.

62

Confidential

Steps in ER Modeling
Step 3: Identify the key attributes
Deptname is the key attribute for the Entity Department, as it identifies the Department uniquely. Course# (CourseId) is the key attribute for Course Entity. Student# (Student Number) is the key attribute for Student Entity. Instructor Name is the key attribute for Instructor Entity.

Step 4: Identify other relevant attributes For the department entity, the relevant attribute is location
For course entity, course name, duration,prerequisite For instructor entity, room#, telephone# For student entity, student name, date of birth

Copyright 2008, Infosys Technologies Ltd.

63

Confidential

Steps in ER Modeling
Step 5: Draw the E-R diagram

Copyright 2008, Infosys Technologies Ltd.

64

Confidential

Case Study Online Retail Application(self study)


Draw an ER diagram of Online Retail Application which allows customer to purchase items from a Retail shop. A customer can register to purchase an item. The customer will provide bank account number and bank name ( the customer may have multiple account no ). After registration each customer will have unique customer Id, user id and password. Customer can purchase one or more items in different quantities . The items can be of different classes based on their prices. Based on the quantity , price of item and discount(if any) on the purchased items, the bill will be generated. A bank account number is required to settle the bill. The application also mentions the information of suppliers who supply the items to the retail shop. The retail shop may give orders to supply the items based on some statistics they maintain about different items.

Copyright 2008, Infosys Technologies Ltd.

65

Confidential

Steps in ER Modeling (self study)


Step 1: Identify the Entities
CUSTOMER

ITEM
SUPPLIER BILL

Copyright 2008, Infosys Technologies Ltd.

66

Confidential

Steps in ER Modeling(self study)


Step 2: Find the relationships
Customer can purchase an item and each purchase will be corresponding to a bill. So it is a ternary relation ship. Items can be ordered to one or more suppliers. One supplier may take order of many items. So many to many relationship between item and supplier. One customer can pay many bill and one bill can be paid by only one customer. So one to many relation ship between customer and bill.

Copyright 2008, Infosys Technologies Ltd.

67

Confidential

Steps in ER Modeling(self study)


Step 3: Identify the key attributes
Customer entity will be identified by CustomerId Item entity will be identified by ItemId Supplier entity will be identified by SupplierId Bill entity will be identified by BillId

Copyright 2008, Infosys Technologies Ltd.

68

Confidential

Steps in ER Modeling(self study)


Step 4: Identify other relevant attributes of Entities and Relationships
For Customer entity the relevant attributes will be (CustomerId,CustomerName, DateOfRegistration, UserId, Password, AccountNo) For Item entity the relevant attributes will be (ItemId, ItemName, UnitOfMeasurement, UnitPrice, Discount, QuantityOnHand, SupplierId,ReOrderLevel,ReOrderQuantity,Class) For Supplier entity the relevant attributes will be (SupplierID, SupplierName, SupplierContactNo) For Bill entity the relevant attributes will be ( BillId, AccountNo, BillAmount, BillDate)
Copyright 2008, Infosys Technologies Ltd.

69

Confidential

Steps in ER Modeling(self study)


Step 4: Identify other relevant attributes of entities and Relationships (Cont..)
For Purchase Relation the relevant attributes will be (QtyPurchased, NetPrice) For OrderedTo relation the relevant attributes will be (OtyOfOrder, OrderDate, DeliveryDate, DeliveryStatus) For Pays relation the relivent attributes will be (AccountNo)

Copyright 2008, Infosys Technologies Ltd.

70

Confidential

Steps in ER Modeling (self study)


Step 5: Draw complete E-R diagram with all attributes

Copyright 2008, Infosys Technologies Ltd.

71

Confidential

Merits and Demerits of ER Modeling


Merits
Easy to understand. Represented in Business Users Language. Can be understood by non-technical specialist. Intuitive and helps in Physical Database creation. Can help in database design. Gives a higher level description of the system.

Demerits
Physical design derived from E-R Model may have some amount of redundancy which may lead to inconsistency. (This will be discussed when we study Normalization on day two)
Sometime diagrams may lead to misinterpretations because of limited information present in the diagram.

Copyright 2008, Infosys Technologies Ltd.

72

Confidential

Summary of ER Modeling
Miscommunication between the application user and the designer is the major source of error. It is always better to represent business findings in terms of picture to avoid miscommunication It is practically impossible to review the complete requirement document by business users.

An E-R diagram is one of the many ways to represent business findings in pictorial format.
E-R Modeling will also help the database design E-R modeling has some amount of inconsistency and anomalies associated with it.

Copyright 2008, Infosys Technologies Ltd.

73

Confidential

Summary
Traditional File Approach Advantages of a DBMS Three layers of abstraction Users of DBMS Database Models Types of Databases Relational Model Basics Keys Conceptual Design ER Modelling ER Modelling Notations ERD Case study Merits & Demerits of ER Modeling

Copyright 2008, Infosys Technologies Ltd.

74

Confidential

Thank You
The contents of this document are proprietary and confidential to Infosys Technologies Ltd. and may not be disclosed in whole or in part at any time, to any third party without the prior written consent of Infosys Technologies Ltd. 2008 Infosys Technologies Ltd. All rights reserved. Copyright in the whole and any part of this document belongs to Infosys Technologies Ltd. This work may not be used, sold, transferred, adapted, abridged, copied or reproduced in whole or in part, in any manner or form, or in any media, without the prior written consent of Infosys Technologies Ltd.

Copyright 2008, Infosys Technologies Ltd.

75

Confidential Confidential

Potrebbero piacerti anche