Advantages of E.R. Model Exceptional conceptual simplicity Visual representation Effective communication tool Integrated with the relational data model.

Slides:



Advertisements
Similar presentations
Chapter 6: Entity-Relationship Model (part I)
Advertisements

Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Concepts of Database Management Seventh Edition Chapter 6 Database Design : ERD Model.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Databases Revision.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Entity-Relationship Model and Diagrams (continued)
Chapter 3: Relational Model
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
CS 405G: Introduction to Database Systems Lecture 4: Relational Model Instructor: Chen Qian.
Relational Model. 2 Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations Extended Relational-Algebra-Operations.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
Relational Model Session 6 Course Name: Database System Year : 2012.
Chapter 4 The Relational Model.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Entity Relationship Model
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
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.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
A Free sample background from © 2006 By Default! R.SARAVANA KUMAR S.NAVEEN Relational Database Model.
1 The Relational Model By Elena Ciriani CS157A February 19, 2004 Professor Lee.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
ICOM 5016 – Introduction to Database Systems Lecture 5b Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations.
CSc340 1b1 The Relational Model Chapter 2 Database Schema Keys Schema Diagrams Relational Query Languages Relational Operations.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Chapter 2 : Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Chapter 2: Relational Model. 2.2Unite International CollegeDatabase Management Systems Chapter 2: Relational Model Structure of Relational Databases Fundamental.
Chapter 2: Relational Model II Relational Algebra basics Relational Algebra basics.
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
International Computer Institute, Izmir, Turkey E-R Model Asst.Prof.Dr.İlker Kocabaş UBİ502 at
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Advantages of E.R. Model Exceptional conceptual simplicity Visual representation Effective communication tool Integrated with the relational data model.
Query Languages Language in which user requests information from the database. Categories of languages Procedural Non-procedural, or declarative “Pure”
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Why it is required to use ERD? Ease of tasks distribution between programmers Evaluation of data consistencies اتساق before building database Efficient.
Data Modeling Using the ERD
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 2: Intro to Relational Model
Chapter 3: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Relational Model.
Chapter 2: Intro to Relational Model
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy.
Presentation transcript:

Advantages of E.R. Model Exceptional conceptual simplicity Visual representation Effective communication tool Integrated with the relational data model Disadvantages of E.R. Model Limited constraint representation Limited relationship representation No data manipulation language Loss of information content

عناصر ال ERD 1) Entity Set وهو الكائن مثل مفهومه في ال OOP ويتم وضعها في التصميم على شكل مستطيل Examples: a computer, an employee, a song, a mathematical theorem. Entities are represented as rectangles. 2) attribute وهو خواص ال كائن وياخذ الشكل البيضاوى 3) Primary key يتم وضع خط تحت ال attribute المستخدم ك مفتاح أساسى 4) Relationship العلاقات ، وهى تحدد كيفية اتصال 2 entities مع بعضهم ، وهى تأخذ شكل الماسي diamond

What is the relationships? Relationships can be thought of as verbs, linking two or more nouns. Examples: an owns relationship between a company and a computer, a supervises relationship between an employee and a department, a performs relationship between an artist and a song, a proved relationship between a mathematician and a theorem. Relationships are represented as diamonds, connected by lines to each of the entities in the relationship

ER diagram for bank

Explanation of the previous example we have 5 entities teacher student subject group Mark كل منهما له attributes وما تحته خط هو المفتاح الأساسي ولدينا 3 علاقات منهما علاقة ثنائية " ما بين 2 entities " belong وعلاقتين ثلاثية " ما بين 3 entities give supervises

University ERD

How to understand ERD

The set of symbols consist of Crow’s feet Zero through Many (crow's feet, O) One through Many (crow's feet, dash) One and Only One (dash, dash) Zero or One (dash, O)

Zero through Many

One through Many

One and Only One (onne)

Zero or One

The relationship between Employee and Project in the example is a many to many relationship. It would exist in logical and physical data models as follows:

One-to-One

example Insurance company for cars, has a customers, each one has a car or more, the company wants a database for liable car accidents. It is required to Analyze the data base and draw ERD

analysis Entities 1- person has name, address, id 2- car has model, year, car id 3- the accident has date, place, report number Relations 1- Owns between person and car 1 to N 2- accident between car, person and accident, it is ternary relation (between car and accident 1to N Between person and accident 1to N

Supermarket ERD like alothem

إعداد : محمد صبحي أبو حطب - الاشراف التربوي / مديرية التربية رام الله -5/ Relationship symbols Relationship degrees specify number of entity types involved Entity symbols A special entity that is also a relationship Relationship cardinalities specify how many of each entity type is allowed

Entity example

ERD collage المقرر المدرس يسجل يدرس الرقم الاسم عدد الساعات المعتمدة الرقم الاسم الهاتف القسم العام الدراسي الفصل الدراسي العلامة العام الدراسي الفصل الدراسي العلامة الطالب الرقمالاسم العنوانالتخصص

Example student sutdentID Name Gender PK Professorstudent teaches student studentID NameGender E MAIL PK

ERD Hospital تاريخ التنويم الاسم الرقم الكمية الدواء الطبيب يعالج يصرف الرقم الاسم الرقم الاسمالهاتف التخصص الغرفة الرقمالهاتف عدد الأسرة 0 المريض ينام في

ERD Library الكتاب المؤلف يستعير يكتب بواسطة الرقم عدد الصفحات عنوان الكتاب الاسم العنوان الالكتروني نوع الاستعارة مدة الاستعارة تاريخ الاستعارة المستعير الرقمالاسم العمل جهة العمل دار النشرتاريخ النشر تاريخ الميلاد

ERD University

2.2.1 Identifier Attributes Candidate key – Attribute (or combination of attributes) that uniquely identifies each instance of an entity type – Some entities may have more than one candidate key Ex: A candidate key for EMPLOYEE is Employee_ID, a second is the combination of Employee_Name and Address. If there is more than one candidate key, need to make a choice. Identifier – A candidate key that has been selected as the unique identifying characteristic for an entity type

Figure 3-9a Simple key attribute

إرشادات حول تعيين المفتاح الاساسي ( او شروطه ): يجب ان لا تتغير قيمته ابدا خلال عمل النظام يجب ان لا تكون قيمته فارغة ( قيمه مطلوبةدائما ) يمكن ان يكون مركباً اذا تعذر الحصول على مفتاح بسيط ان لا تتكرر قيمته ان يكون فريدأ ومميزا لحاله واحدة على الاكثر من سجلات الكيان

صفة للعلاقة العلاقة يمكن تمثيلها بشكل معين وخطوط بين الكيانات وهي (اكمل) وتقرا ان الموظف اكمل الدورة وتكون بين كيان الموظف والدورة ونوع العلاقة سيبحث فيما بعد

Cardinality درجة العلاقة يقصد به عدد الكيانات المرتبطة فيما بينها كيان واحد يرتبط مع كيان آخر من نفس نوع الكيان ومثال ذلك الموظف يكون مديرا لموظفين آخرين هنا يرتبط نوعين مختلفين من الكيانات مع بعضهما هنا أنواع مختلفة من الكيانات ترتبط مع بعضها وتكون اكثر من نوعين

AUTOMOBILE ENGINEPRODUC T VENDOR INSTRUCTOR SKILL DEPARTMENT STUDENT INSTRUCTOR STUDENT EMPLOYEE supervises SALES ORDERS INV. ITEMSORDER ITEMS SALES ORDERS INV. ITEMS IS SUPERVISED BY

أمثله عن أنواع الروابط

صفات أم روابط أم كيان ؟؟ ان الصفات الروابط يمكن تحويلها الى كيانات وذلك عندما نواجه صفات مرتبطة مركبه او صفات متعددة القيم وبذلك يمكننا تمثيلها بواسطة كيانات مشتقه جديدة

Car rent

Train teckets

Sql summary create table emp انشاء جدول موظفين باسم emp لبنك معين يتكون من الحقول التالية (emp_number(4) primary key, ename varchar2(15), Deptno number(7), Mgr varchar2(15), sal number(7)); select ename,sal عرض أسماء ورواتب جميع الموظفين from emp; select ename,mgr عرض أسماء الموظفين وأرقام مدرائهم from emp; select ename,sal عرض أسماء ورواتب موظفي الدائرة رقم 20 from emp where deptno = 20;

create table account انشاء جدول الحسابات باسم اكاونت لبنك معين يتكون من الحقول التالية (acc_no number(4) primary key, acc_name varchar2(15), balance number(7)); insert into account ادخال في هذا الجدول المعلومات التالية values (1212,'firas', ); insert into account ادخال في هذا الجدول المعلومات التالية values (3334,'ali', ); update account إضافة 100 ريال على هذا الحساب set balance = balance where acc_no = 1212; alter table account إضافة عمود جديد على الجدول add notes varchar2(20); delete account حذف حساب رقم 3334 where acc_no = 3334; drop table account; حذف الجدول نهائياً

Example on creating table CREATE TABLE mytab( id int(11) NOT NULL auto_increment PRIM ARY KEY, Fname varchar(30) NOT NULL, Lname varchar(30) NOT NULL, age int(11) NOT NULL, )

To connect to db using php

Query and display "; $i=0; while( $i "; echo" $fname "; echo" $lname "; echo" $age "; echo" $id "; echo" [Edit] "; echo" [delete] "; echo" "; ++$i; } echo" "; mysql_close($con); // نهاية التتعامل مع محرك القاعده ?>

To update "; لاحظ في بداية النموذج أننا كتبنا : action='$PHP_SELF' وتعني أن متغيرات النموذج ترسل لنفس الصفحة echo " "; echo " Edit The Info "; extract($_GET); // والوارده بهذه الطريقه GET استخراج المتغيرات من مصفوفه extract($_POST); $con=mysql_connect("localhost","root",""); if(!$con){ die('can not connect'.mysql_error()); } mysql_select_db(mydb,$con); $query1 = "select * from mytab where id ='$id'"; $result1 = mysql_query($query1);

// هنا نطبع البيانات داخل مربعات نصوص while($row = mysql_fetch_object($result1)) جلب النتائج على شكل صف صف ووضعها في المتغير $row { echo " First Name Fname'> "; echo " Last Name Lname'> "; echo " Age age'> "; $id = $row->id; } echo " "; echo " "; /* نهاية النموذج */

extract($_GET); extract($_POST); if ($update) { // إذا ضغط المستخدم على الزر if($fname == "" || $lname == "" || $age == "" ) {// إذا كان أحد الحقول فارغ ما يكمل die(" You left one or more fields blank. "); } $query2 = "update mytab set fname='$fname', lname ='$lname', age='$age' where id='$id'"; mysql_query($query2); echo " Your record has been updated "; } mysql_close(); ?>

Delete code in php

Data anomalies problem مشكلة تكرار البيانات Adding problems : we cant add new department unless it as employee because the primary key is Empno Updating and deleting problem : to update the Loc field from jeddah to riadh for one employee will corapt the other employee locations

To solve those problems Function dependency FD -  A-  B Means B is depending Functionally on A I.e A value define B value Example: For each empl. Only unique name For each empl. Only unique dept

FD1: Empno  Ename FD2: Empno  Deptno We can write it as: FD1: Empno  Ename,Deptno FD :Functional Dependency

Basic Structure Formally, given sets D 1, D 2, …. D n a relation r is a subset of D 1 x D 2 x … x D n Thus a relation is a set of n-tuples (a 1, a 2, …, a n ) where each a i  D i Example: if customer-name = {Jones, Smith, Curry, Lindsay} customer-street = {Main, North, Park} customer-city = {Harrison, Rye, Pittsfield} Then r  customer-name x customer-street x customer-city r = { (Jones, Main, Harrison), (Smith, North, Rye), (Curry, North, Rye), (Lindsay, Park, Pittsfield)} is a relation over customer-name x customer-street x customer-city

Attribute Types Each attribute of a relation has a name The set of allowed values for each attribute is called the domain of the attribute Attribute values are (normally) required to be atomic, that is, indivisible – E.g. multivalued attribute values are not atomic – E.g. composite attribute values are not atomic The special value null is a member of every domain The null value causes complications in the definition of many operations – we shall ignore the effect of null values in our main presentation and consider their effect later

Relation Schema A 1, A 2, …, A n are attributes R = (A 1, A 2, …, A n ) is a relation schema E.g. Customer-schema = (customer-name, customer-street, customer-city) r(R) is a relation on the relation schema R E.g.customer (Customer-schema)

Relation Instance Jones Smith Curry Lindsay customer-name Main North Park customer-street Harrison Rye Pittsfield customer-city customer attributes (or columns) tuples (or rows) The current values (relation instance) of a relation are specified by a table An element t of r is a tuple, represented by a row in a table

Determining Keys from E-R Sets Strong entity set. The primary key of the entity set becomes the primary key of the relation. Weak entity set. The primary key of the relation consists of the union of the primary key of the strong entity set and the discriminator of the weak entity set. Relationship set. The union of the primary keys of the related entity sets becomes a super key of the relation. – For binary many-to-one relationship sets, the primary key of the “many” entity set becomes the relation’s primary key. – For one-to-one relationship sets, the relation’s primary key can be that of either entity set. – For many-to-many relationship sets, the union of the primary keys becomes the relation’s primary key

Schema Diagram for the Banking Enterprise

Query Languages Language in which user requests information from the database. Categories of languages – procedural – non-procedural “Pure” languages: – Relational Algebra – Tuple Relational Calculus – Domain Relational Calculus Pure languages form underlying basis of query languages that people use.

Relational Algebra Procedural language Six basic operators – select – project – union – set difference – Cartesian product – rename The operators take two or more relations as inputs and give a new relation as a result.

Select Operation – Example Relation r ABCD   σ A=B ^ D > 5 (r) ABCD  

Select Operation Notation:  p (r) p is called the selection predicate الاختيار المبنى عليه Defined as:  p ( r) = {t | t  r and p(t)} Where p is a formula in propositional calculus consisting of terms connected by :  (and),  (or),  (not) Each term is one of: op or where op is one of: =, , >, . <.  Example of selection:  branch-name=“Perryridge ” (account)