Modeling Data in the Organization Enrollment Key: basdat 2011 Kuliah 3 Basis Data Disampaikan oleh: Annisa, M.Kom.
Outline Business Rules and Scope of Business Rules Modeling the Rules of Organization Data Names and Definitions Modeling Entities Conceptual Database Design: ER data model Modeling Attributes Modeling Relationships © Pearson Education Limited 1995, 2005
Business Rules and Scope of Business Rules Important policy statement, but no impact on databases “Friday is business casual dress day” “A student may register for a section of a course only if he or she has successfully completed the prerequisites for that course”
Data Names and Definitions Relate to business, not technical : Customer, not File10, Bit7, X, etc. A course is a module of instruction in a particular subject area Meaningful, Readable : GradePointAverage, not AverageGradeRelativetoCust Unique : HomeAddress VS CampusAddress Composed of Words Taken from an Approved List: CUST for Customer Repeatable: StudentBirthDate, EmployeeBirthDate
Entity-Relationship (ER) Modeling Entity Relationship (ER) Diagram A detailed, logical representation of the entities, associations and data elements for an organization or business Notation uses three main constructs Entities Relationships Attributes
E-R Model Constructs Entities: Entity instance–person, place, object, event, concept (often corresponds to a row in a table) Entity Type–collection of entities (often corresponds to a table) Relationships: Relationship instance–link between entities (corresponds to primary key-foreign key equivalencies in related tables) Relationship type–category of relationship…link between entity types Attribute–property or characteristic of an entity or relationship type (often corresponds to a field in a table) 2
Basic E-R notation Entity symbols Attribute symbols Relationship symbols A special entity that is also a relationship Relationship cardinalities specify how many of each entity type is allowed Relationship degrees specify number of entity types involved 8
Basic E-R notation Examples of entities: Person: EMPLOYEE, STUDENT, PATIENT Place: STORE, WAREHOUSE Object: MACHINE, PRODUCT, CAR Event: SALE,REGISTRATION, RENEWAL Concept: ACCOUNT, COURSE
Strong Entity of Dream Home Dream Home adalah perusahaan yang bergerak di bidang penyewaan rumah. Dream Home memiliki banyak cabang di masing-masing ibukota propinsi, dimana setiap cabang memiliki banyak pegawai. Setiap pegawai memperoleh asuransi kesehatan untuk dirinya dan keluarganya. Property didaftarkan oleh Owner. Setiap owner boleh mendaftarkan lebih dari satu propertinya. Setiap client boleh menyewa lebih dari satu property. Setiap client mendaftarkan preferensi tentang rumah yang dikehendakinya. Client mengetahui property yang disewakan dari iklan yang dipasang oleh perusahaan. Setiap rumah dapat dilihat oleh client. Jika client setuju untuk menyewa rumah tersebut, maka akan dilakukan perjanjian kontrak.
Strong Entity of Dream Home BRANCH EMPLOYEE PROPERTY OWNER CLIENT
Weak Entity of Dream Home Dream Home adalah perusahaan yang bergerak di bidang penyewaan rumah. Dream Home memiliki banyak cabang di masing-masing ibukota propinsi, dimana setiap cabang memiliki banyak pegawai. Setiap pegawai memperoleh asuransi kesehatan untuk dirinya dan keluarganya. Property didaftarkan oleh Owner. Setiap owner boleh mendaftarkan lebih dari satu propertinya. Setiap client boleh menyewa lebih dari satu property. Setiap client mendaftarkan preferensi tentang rumah yang dikehendakinya. Client mengetahui property yang disewakan dari iklan yang dipasang oleh perusahaan. Setiap rumah dapat dilihat oleh client. Jika client setuju untuk menyewa rumah tersebut, maka akan dilakukan perjanjian kontrak.
Weak Entity of Dream Home DEPENDENT BRANCH EMPLOYEE PROPERTY OWNER CLIENT
Associative Entity of Dream Home Dream Home adalah perusahaan yang bergerak di bidang penyewaan rumah. Dream Home memiliki banyak cabang di masing-masing ibukota propinsi, dimana setiap cabang memiliki banyak pegawai. Setiap pegawai memperoleh asuransi kesehatan untuk dirinya dan keluarganya. Property didaftarkan oleh Owner. Setiap owner boleh mendaftarkan lebih dari satu propertinya. Setiap client boleh menyewa lebih dari satu property. Setiap client mendaftarkan preferensi tentang rumah yang dikehendakinya. Client mengetahui property yang disewakan dari iklan yang dipasang oleh perusahaan. Setiap rumah dapat dilihat oleh client. Jika client setuju untuk menyewa rumah tersebut, maka akan dilakukan perjanjian kontrak.
Associative Entity of Dream Home DEPENDENT BRANCH EMPLOYEE LEASE PROPERTY VIEW ADVERTISE OWNER CLIENT
Attributes Attribute–property or characteristic of an entity or relationship type Classifications of attributes: Required versus Optional Attributes Simple versus Composite Attribute Single-Valued versus Multivalued Attribute Stored versus Derived Attributes Identifier Attributes 15 5
Simple and composite identifier attributes The identifier is boldfaced and underlined 16 14
Composite, multivalued and derived attribute Composite: An attribute broken into component parts Entity with multivalued attribute (Skill) and derived attribute (Years_Employed) Multivalued an employee can have more than one skill Derived from date employed and current date 17 12
Identifiers (Keys) Identifier (Key)–An attribute (or combination of attributes) that uniquely identifies individual instances of an entity type Simple versus Composite Identifier Candidate Identifier–an attribute that could be a key…satisfies the requirements for being an identifier Will not change in value Will not be null 18 6
Attributes of Dream Home Entities EMPLOYEE Employee_Id Employee_Address … DEPENDENT Dependent_Name Date_Of_Birth … BRANCH Branch_Id Branch_Address … PROPERTY Property_Id Property_Address Types No_Of_Rooms … CLIENT Client_Id Client_Address Client_Telp Preferred_type … OWNER Owner_Id Owner_Address Owner_Telp …
Relationships Relationship Types vs. Relationship Instances The relationship type is modeled as lines between entity types…the instance is between specific entity instances Relationships can have attributes These describe features pertaining to the association between the entities in the relationship Two entities can have more than one type of relationship between them (multiple relationships) Associative Entity–combination of relationship and entity 20
Relationship types and instances a) Relationship type b) Relationship instances 21 17
Degree of Relationships Degree of a relationship is the number of entity types that participate in it Unary Relationship Binary Relationship Ternary Relationship 22 16
Cardinality of Relationships One-to-One Each entity in the relationship will have exactly one related entity One-to-Many An entity on one side of the relationship can have many related entities, but an entity on the other side will have a maximum of one related entity Many-to-Many Entities on both sides of the relationship can have many related entities on the other side 23
Degree of relationships One entity related to another of the same entity type Entities of two different types related to each other Entities of three different types related to each other 24 8
Examples of relationships of different degrees a) Unary relationships 25 22
Examples of relationships of different degrees (cont.) b) Binary relationships 26 22
Examples of relationships of different degrees (cont.) c) Ternary relationship Note: a relationship can have attributes of its own 27 22
Cardinality Constraints Cardinality Constraints - the number of instances of one entity that can or must be associated with each instance of another entity Minimum Cardinality If zero, then optional If one or more, then mandatory Maximum Cardinality The maximum number 28 29
Examples of cardinality constraints a) Mandatory cardinalities A patient history is recorded for one and only one patient A patient must have recorded at least one history, and can have many 29 1
Examples of cardinality constraints (cont.) b) One optional, one mandatory An employee can be assigned to any number of projects, or may not be assigned to any at all A project must be assigned to at least one employee, and may be assigned to many 30 1
Examples of cardinality constraints (cont.) c) Optional cardinalities A person is married to at most one other person, or may not be married at all 31 1
Examples of multiple relationships a) Employees and departments Entities can be related to one another in more than one way 32 40
Examples of multiple relationships (cont.) b) Professors and courses (fixed lower limit constraint) Here, min cardinality constraint is 2 33 40
Multivalued attributes can be represented as relationships simple composite 34
TUGAS Kerjakan perkelompok didiskusikan hari Rabu depan