0 valutazioniIl 0% ha trovato utile questo documento (0 voti)
61 visualizzazioni72 pagine
Entity-relationship Model is based on three fundamental concepts. Entity set - relationship set - attributes entity is a thing in the real world with its own existence, and is different from each other. Attribute value that describe each entity become a major part of the data store in the database.
Entity-relationship Model is based on three fundamental concepts. Entity set - relationship set - attributes entity is a thing in the real world with its own existence, and is different from each other. Attribute value that describe each entity become a major part of the data store in the database.
Entity-relationship Model is based on three fundamental concepts. Entity set - relationship set - attributes entity is a thing in the real world with its own existence, and is different from each other. Attribute value that describe each entity become a major part of the data store in the database.
Its components are: rectangles representing entity sets. ellipses representing attributes. diamonds representing relationship sets. lines linking attributes to entity sets and entity sets to relationship sets.
Entity-relationship Model is based on three fundamental concepts. Entity set Relationship set Attributes
Entity: Entity is a thing in the real world with its own existence, and is different from each other. For example: car, man, house, company etc. Entity is represent graphically by rectangle.
The object of entity has two types of existence. 1. Physical existence-person, car etc. 2. Conceptual existence-company, job, university course.
. Company Attributes Every entity has different attributes. Attribute is used to described properties of desire entity. For example: if entity is employee, then its attributes are employee_id, name, age, salary, designation etc. The attribute value that describe each entity become a major part of the data store in the database.
Types of attributes Simple attribute it is also called atomic attribute. Attributes cannot divided further into small sub parts are called simple attribute. For example: Roll No. Attribute is graphically represented by ellipse.
Attribute is link with correspondent entity. Roll No Composite attribute Attributes can be divided into smaller subparts, which represent more basic attributes with independent meaning, such attribute is known as composite attribute. Composite attribute is divided into subparts hence it maintain hierarchy. For example
Student_Name First_Name Middle_Name Last_Name Mother_Name Single value attribute The attribute contains only one (single) value, such attribute is called single value attribute. For example Person having only one original name. since name is single value attribute. Student having only one unique roll-no. since roll-no is single value attribute. Multi-Valued attribute The attribute contain more then one different numbers of value, such attribute is called multi-valued attribute. For example One person having two addresses. One person having more than one contact number. Multi-valued attribute is graphically shown by following way. Phone_no Stored attribute and derived attribute There are many attributes which are dependant on the other attribute. For example: The grade (First class with distinction, first class, second class, higher second class, pass class) which are depend on the total of marks. In this case total is the stored attribute. The attribute grade is depends on total (Attribute) and hence grade is derived attribute. Derived attribute are graphically shown by dotted line ellipse. For example
Another example is the age of person which depends on the birth_date of that person and since stored attribute is birth_date and dervied attribute is age.
grade Null attribute Some attributes are sometimes not necessary in future. In that case they may not have an applicable value for that attribute. The attributes having no value, a special value are called null is created. For example : Mobile no. This attribute is not applicable every times since null value place over there. Entity set and Entity types An entity set is set of entity of same types. An entity types defines a collection (or set) of entities that have same attributes. Primary key: Objects are represented by their attributes and, as objects are inter- distinguishable, a subset of these attributes forms a primary key. Strong entity set: Entity types that have primary keys are called strong entity. For example: Student is strong entity type because it associates with primary key Roll-no. It is graphically shown by as follows.
strong entity set Roll-no Student Weak entity set: the entity that does not have sufficient primary key is called weak entity set. It is graphically shown as follows,
Weak entity set Fruit_name Weight Fruit Relationship set The relationship is an association (link) among two or more that entities. The relation are shown graphically in diamond shape. For example: student are studying in college
ER diagram (relationship)
student Studying in college We can define relationship between two participant entities. Primary Key Primary Key
Fig: Tabular representation of
relation
Composite Primary Key Docto r_No Doctor_ Name 1 Vinod 2 Akshay 3 Minal 4 Kanchan 5 Rahul 6 Atul Hosp_N o Hosp_N ame 1 Ruby 2 Sasoon 3 Bharti 4 K-Navale 1 1 2 3 3 2 4 2 5 4 6 1 Degree of relationship type The degree of relationship type is the number of participating entity types. A. Uniary Relationship If one entity associate with itself then such relationship is called as Uniary Relationship. E.g. One person at a time marry with only one person
1
1
Person marria ge pid Pname Gend er B. Binary Relationship If two entity sets exist in a relationship, such relationship is known as binary relationship. For example:
Student Studyi ng in College Roll-No Name Address College_ Code CName C_address C. Ternary Relationship If three entity exists in relationship is known as ternary relationship.
Works for Person Name Address Phone Company Compan y name Address Business Business type involve ment Name 19 Process of Database Design Logical Design Based upon the conceptual data model Four key steps 1. Develop a logical data model for each known user interface for the application using normalization principles. 2. Combine normalized data requirements from all user interfaces into one consolidated logical database model 3. Translate the conceptual E-R data model for the application into normalized data requirements 4. Compare the consolidated logical database design with the translated E-R model and produce one final logical database model for the application
9.19 Keys: super key: of an entity set is a set of oneor more attributes whose values uniquelydetermine each entity. candidate key of an entity set is aminimal super key Customer_id is candidate key of customer account_number is candidate key of account
Although several candidate keys may exist,one of the candidate keys is selected to be the primary key .
Design Issues Use of entity sets vs. attributes Choice mainly depends on the structure of the enterprisebeing modeled, and on the semantics associated with theattribute in question. Use of entity sets vs. relationship sets Possible guideline is to designate a relationship set todescribe an action that occurs between entities
Binary versus n-ary relationship sets Although it is possible to replace any nonbinary (n-ary, for n> 2) relationship set by a number of distinct binary relationship sets, a n-ary relationship set shows moreclearly that several entities participate in a singlerelationship.
Mapping Cardinality The cardinality ratio for a binary relationship specifies the number of relationship. There are four types of mapping cardinality. 1. one-to-one 2. One-to-many 3. Many-to-one 4. Many-to-many Examples One-to-one: Every department has only one manager. One state has only one capital Maharashtra Gujrat Goa Karnatak Mumbai Gandhinagar Panaji Banglore Many-to-one Many workers works on one department. Many railway stations in one city.
Railway Station City
Shivaji-Nagar Pune-Station Vashi Dadar Pune
Mumbai One-to-many One student takes many subjects. At single platform many trains arrived Trains Platform No.
1 2 3 4 5
Sinhgad Exp. Shatal Koyna Exp. Sikandarabad Manmad Exp. Zelam Local Many-to-many Many college offers many courses.
Course College Sinhgad
Modern
MIT
BCS
BCA
MCS
MCM
BBA
ER diagram of above all relationship is drawn as follows One-to-one
1 1
Many-to-one
M 1 State Having Capital Station Placed in City One-to-Many
1 M
Many-to-Many
M M Platform End stops for Trains College Offers Courses Entity-Relationship Diagram Sr No Symbol Meaning 1 Entity Set 2
Weak Entity Set 3
Relationship 4
Attribute 5
Multivalued attribute 6
Derived Attribute 7
Connector 31 Relational Database Model Data represented as a set of related tables or relations Relation A named, two-dimensional table of data. Each relation consists of a set of named columns and an arbitrary number of unnamed rows Properties Entries in cells are simple Entries in columns are from the same set of values Each row is unique The sequence of columns can be interchanged without changing the meaning or use of the relation The rows may be interchanged or stored in any sequence 9.31 32 Relational Database Model Well-Structured Relation A relation that contains a minimum amount of redundancy and allows users to insert, modify and delete the rows without errors or inconsistencies
9.32 33 Transforming E-R Diagrams into Relations It is useful to transform the conceptual data model into a set of normalized relations Steps 1. Represent entities 2. Represent relationships 3. Normalize the relations 4. Merge the relations
9.33 34 Transforming E-R Diagrams into Relations
The primary key must satisfy the following two conditions a. The value of the key must uniquely identify every row in the relation b. The key should be non redundant
9.34 35 9.35 36 37 Transforming E-R Diagrams into Relations 2. Represent Relationships Binary 1:N Relationships Add the primary key attribute (or attributes) of the entity on the one side of the relationship as a foreign key in the relation on the right side The one side migrates to the many side
9.37 38 9.38 39 Transforming E-R Diagrams into Relations Binary or Unary 1:1 Three possible options a. Add the primary key of A as a foreign key of B b. Add the primary key of B as a foreign key of A c. Both
9.39 40 Transforming E-R Diagrams into Relations 2. Represent Relationships (continued) Binary and higher M:N relationships Create another relation and include primary keys of all relations as primary key of new relation
9.40 41 9.41 42 Transforming E-R Diagrams into Relations Unary 1:N Relationships Relationship between instances of a single entity type Utilize a recursive foreign key A foreign key in a relation that references the primary key values of that same relation Unary M:N Relationships Create a separate relation Primary key of new relation is a composite of two attributes that both take their values from the same primary key
9.42 43 9.43 44 Translating ER-Diagrams to Table Definitions 45 Relations vs. Tables We show how to translate ER-Diagrams to table definitions Sometimes, people translate ER-Diagrams to relation definitions, which is more abstract than table definitions. e.g., Student(ID, Fname, Lname); table definitions contain, in addition, constraints and datatypes 46 Translating Entities General Rule: Create a table with the name of the Entity. There is a column for each attribute The key in the diagram is the primary key of the table Actor id name address birthday Extended ER features There are three types of extended features. 1. Specialization 2. Generalization 3. Aggregation Specialization Specialization is the process of defining a set of subclasses of an entity types; this entity types is called the super-class of the specialization. The set of subclass that form a specialization is defined on the basis of same distinguishing characteristics of the entity in the super-class. Specialization used IS-A Relationship For example
Specialization Teaching Staff IS-A Permanent Teaching Staff Visiting Teaching Staff To overview of above diagram, we noted that specialization defines the different types of higher entity. We can extends as follows:
Fig: Adding Specialization Teaching Staff IS-A Permanent Teaching Staff Visiting Teaching Staff IS-A Principal Lecturer Professors HOD Topdown design process; we designate subgroupings within an entity setthat are distinctive from other entities in the set.
These subgroupings become lowerlevel entity sets that have attributes or participate in relationships that do not apply to the higherlevel entity set.
Depicted by a triangle component labeled ISA (E.g.customer is aperson ).
Attribute inheritance a lowerlevel entity set inherits all the attributesand relationship participation of the higherlevel entity set to which it islinked
Generalization Several entities are generalized into common entity set; which are identify their common features and generalize then into single super class of which the original entity types are special subclasses. For example
(a) (b) Permanent Teaching Staff Visiting Teaching Staff Salary Post Name subject Name College Name Subject Salary Permanent Teaching Staff Visiting Teaching Staff Teaching Staff IS-A Name Subject Salary Post College Name A bottomup design process combine a number of entity setsthat share the same features into a higherlevel entity set. Specialization and generalization are simple inversions of each other; they are represented in an ER diagram in the same way. The terms specialization and generalization are used interchangeably
Specialization and Generalization Can have multiple specializations of an entity set based on differentfeatures. E.g. permanent_employee vs.temporary_employee , in addition to officer vs. secretary vs.teller Each particular employee would be a member of one of permanent_employee or temporary_employee and also a member of one of officer , secretary , or teller The ISA relationship also referred to as superclass subclass relationship
Completeness constraint specifies whether or not an entityin the higherlevel entity set must belong to at least one of thelowerlevel entity sets within a generalization. Total : an entity must belong to one of the lower- level entitysets Partial : an entity need not belong to one of the lowerlevelentity sets
Aggregation An aggregation is a process of an abstraction through which relationships are treated as higher level entities. Example M M
1 Lecturers Takes Lectures Manage by Principal Consider the ternary relationship works_on , which we saw earlier Suppose we want to record managers for tasks performed by anemployee at a branch
job Employee branch manager Works _on manag es Relationship sets works_on and manages represent overlapping information Every manages relationship corresponds to a works_on relationship However, some works_on relationships may not correspond to any manages relationships So we cant discard the works_on relationship Eliminate this redundancy via aggregation Treat relationship as an abstract entity Allows relationships between relationships Abstraction of relationship into new entity
Without introducing redundancy, the following diagram represents: An employee works on a particular job at a particular branch An employee, branch, job combination may have an associated manager
Case Studies A travel agency maintains various taxis. The list of drivers and their license number is also, maintained by them. For every taxis, a log book records details about damage/ accidents that might have taken place along with the date and drivers name and other details E-R diagram
1 M
1
1
Taxis has Drivers has Log tno Model dno Name Lno recno Type Date Location Identified entities with primary key
Relational model with all entity taxis(tno,model) drivers(dno, name, ino, tno) log(recno,type,date,location) In log the type is either damage or accident.
Entity Primary key Taxis Tno Drivers Dno,tno Log recno Relationship (As per shown in ER diagram) 1. One taxi has Many Drivers(one-to-many) 2. One taxi has One log book (one-to-one) Tabular representation Taxis Log
Primary Drivers Primary key Key
Primary Foreign Key Key Tno Model Regno Type Date Location Dno Name License No Tno Assignment Design a database for a car insurance company that has a set of customers, each of whom owns one or more cars. Each car has associated with it zero to any number of record accidents. A database should provide following details to user: 1. identify all entities. 2. Identify all relations 3. E-R diagrams 4. Relational model ER- Diagram
1 M 1
M Customers Car has Accident has cno
Name Address cano Model Insure date
Lno
City
Rno Date Location
City
key any subset of a relation is called key. super key a key is called super key if it is sufficient to identify a unique tuple of a relation. candidate key a minimal super key is called candidate key i.e. no proper subset of a candidate key is super key. primary key a candidate key chosen as a principal to identify a unique tuple of a relation. foreign key a key of a relation which is a primary key of some other relation in the relational schema. domain The set of possible values for an attribute is called the domain of the attribute e.g.: The domain of attribute marital status is having four values: single, married, divorced or widowed. The domain of the attribute month is having twelve values ranging from January to December.
Database Schema Definition : Overall logical design of data base. Schema contains 'No of records + Type of data + No of attributes' External level or Sub schema logical schema :A logical schema is a data model of a specific problem domain expressed in terms of a particular data management technology physical schema :Physical schema is a term used in data management to describe how data is to be represented and stored (files, indices, et. al) in secondary storage using a particular database management system (DBMS) (e.g., Oracle RDBMS, Sybase SQL Server, etc.).
Levels of database schema 1. Conceptual schema, a map of concepts and their relationships 2. Logical schema, a map of entities and their attributes and relations 3. Physical schema, a particular implementation of a logical schema 4. Schema object, Oracle database object 5. Schema is the over all structure of the database
Database Instance Definition: The term instance is typically used to describe a complete database environment, including the RDBMS software, table structure, stored procedures and other functionality. It is most commonly used when administrators describe multiple instances of the same database.
Definition: The information stored in database at the particular movement is called instance. Also Known As: environment is the place where the data can be stored in manageable manner. Examples: An organization with an employees database might have three different instances: production (used to contain live data), pre-production (used to test new functionality prior to release into production) and development (used by database developers to create new functionality).