Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Advantages of E.R. Model Exceptional conceptual simplicity Visual representation Effective communication tool Integrated with the relational data model."— Presentation transcript:

1 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

2 عناصر ال 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

3 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

4 ER diagram for bank

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

6 University ERD

7 How to understand ERD

8 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)

9 Zero through Many

10 One through Many

11 One and Only One (onne)

12 Zero or One

13 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:

14 One-to-One

15 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

16 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

17

18 Supermarket ERD like alothem

19 إعداد : محمد صبحي أبو حطب - الاشراف التربوي / مديرية التربية رام الله -5/2007 19 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

20 Entity example

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

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

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

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

25 ERD University

26

27 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

28 Figure 3-9a Simple key attribute

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

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

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

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

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

34

35

36

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

38

39

40

41 Car rent

42 Train teckets

43 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;

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

45 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, )

46 To connect to db using php

47 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); // نهاية التتعامل مع محرك القاعده ?>

48 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);

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

50 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(); ?>

51 Delete code in php

52 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

53 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

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

55 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

56 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

57 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)

58 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

59 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

60 Schema Diagram for the Banking Enterprise

61 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.

62 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.

63 Select Operation – Example Relation r ABCD   1 5 12 23 7 3 10 σ A=B ^ D > 5 (r) ABCD   1 23 7 10

64 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)


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

Similar presentations


Ads by Google