Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
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
Confidential
Course Objectives
Introduction of basic RDBMS concepts Familiarization with SQL
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
Aggregate Functions Group By and Having clause Joins Independent Sub Queries Correlated Sub queries Use of EXISTS and NOT EXISTS
Views DCL
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
Confidential
Confidential
File System
Customer_Details.dat
Customer_Loan.dat
Customer_Fixed_Deposit.dat
Customer_Transaction.dat
10
Confidential
Data Isolation
Program / Data Dependence Lack of Flexibility Concurrent Access Anomalies
11
Confidential
12
Confidential
DBMS
File System
Bank Database
13
Confidential
DBMS
14
Confidential
Three-layer Architecture
External / View Level
(Individual User View)
External Schema A
External Schema B
External Schema C
Conceptual Schema
Internal Schema
15
Confidential
External Schemas
External View A
External View B
DBMS
Conceptual Schema
Conceptual view
16
Confidential
External
Conceptual
TYPE = BYTE (4), OFFSET = 0 TYPE = BYTE (4), OFFSET = 4 TYPE = BYTE (7), OFFSET = 8
Internal
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
18
Confidential
Advantages of a DBMS
Data independence Reduction in data redundancy Better security Better flexibility Effective data sharing
19
Confidential
Data Models
Definition of data model : A conceptual tool used to describe : Data Data relationships
Data semantics
Consistency constraints
20
Confidential
Record based logical model Hierarchical data model Network data model Relational data model
21
Confidential
Smith_Mike@yahoo.com
1011 8755.00 1011 8755.00 103 Langer G. Justin 3421 Savings Plainsboro Langer_Justin@yahoo.com
2010 2555.00
2015 2000.00
22
Confidential
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
23
Confidential
24
Confidential
25
Confidential
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
26
Confidential
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.
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}
28
Confidential
29
Confidential
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
30
Confidential
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
31
Confidential
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
32
Confidential
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
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
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)
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
35
Confidential
36
Confidential
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.
37
Confidential
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.
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
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.
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
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)
44
Confidential
Relationship Participation
Total : Every entity instance must be connected through the relationship to
another instance of the other participating entity types
45
Confidential
ER MODELING - NOTATIONS
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.
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
49
Confidential
Composite attribute
floor building
E#
Employee
Designation
50
Confidential
Unary Relationship
Employee
Manages
51
Confidential
Role names
Role names may be added to make the meaning more explicit
subordinate
Employee
1
Manager
Manages
52
Confidential
Binary Relationship
Employee
Works for
Department
53
Confidential
Ternary Relationship
Medicine
Doctor
Prescription
Patient
54
Confidential
Relationship participation
Employee
head of
department
55
Confidential
Attributes of a Relationship
Medicine
Doctor
Prescription
Patient
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
57
Confidential
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
59
Confidential
Steps in ER Modeling
Step 1: Identify the Entities
DEPARTMENT
STUDENT
COURSE INSTRUCTOR
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
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
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
63
Confidential
Steps in ER Modeling
Step 5: Draw the E-R diagram
64
Confidential
65
Confidential
ITEM
SUPPLIER BILL
66
Confidential
67
Confidential
68
Confidential
69
Confidential
70
Confidential
71
Confidential
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.
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.
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
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.
75
Confidential Confidential