Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Modelling. EAR model This modelling language allows a very small vocabulary: Just as English has nouns, verbs, adjectives, pronouns.., EAR models.

Similar presentations


Presentation on theme: "Data Modelling. EAR model This modelling language allows a very small vocabulary: Just as English has nouns, verbs, adjectives, pronouns.., EAR models."— Presentation transcript:

1 Data Modelling

2 EAR model This modelling language allows a very small vocabulary: Just as English has nouns, verbs, adjectives, pronouns.., EAR models have only 3 central concepts –Attribute – a simple, atomic data item like a date, a name, a number [also called Property or Field] –Entity – a group of attributes which are all related to the same thing [also called Entity Type or Class] –Relationship – a relationship between Entities.

3 MMS Photo : EAR diagram Entity Attribute Relationship Primary key Data Type Each Member has created many Photos Each Photo created by exactly one Member Diagram generated by QSEE

4 Case Tool - QSEE is a free download for individual use is available in the lab enables a wide range of diagram types to be created –Entity-relationship diagram –With generation of SQL for creating a database (with some fixes  )

5 Entity (type) Typically represents a type of thing – a person, department, photo Like a Class in Object-Orientation Has a name –Name becomes the name of the table in a database –I prefer a singular noun – Employee, Department. The table will contain a varying number of entity instances but the Entity Type is singular Has attributes or properties (which become fields or columns in a database) Entity instances are related (linked) to other entity instances – relationships Has an Annotation (in QSEE) –Text to describe the scope of this type (what things can be one of these), the meaning and usage, a typical example.

6 Attribute Name –Must be unique across the Entity –Less confusion if unique across the database –Avoid SQL reserved words Type (data type) –SQL provides a set of available data types – essential ones are: integer – a whole number numeric – number with decimal part character – fixed length string varchar – variable length string date – hold dates like 2005/10/14 blob – a very large field

7 Enumeration A restricted set of values –e.g. the valid images types to be stored in the photo album First define the type Then it can be used as a data type for an attribute.

8 Other attribute ‘attributes’ in QSEE Key –Tick if this attribute forms part of the primary key – the fields which together uniquely identify each entity instance in the table Null –Tick if this attribute may be left undefined Unique –Tick if each entity instance must have a unique value in the table Auto-increment –[Cannot set in QSEE at present] –When adding a new record, this attribute will be given the next value in sequence Annotation –Descriptive text – what the attribute represents, legal values, example values…

9 Relationship CARDINALITY M1 P4P5P1 M2 P3 P7 M4 member photo One-one One-many Many-many

10 It is hard to get this notation the right way round. –Always read it both ways Every X is related to how many Y’s? Every Y is related to how many X’s?

11 Relationship OPTIONALITY M1 P4P5P1 M2 P3 P7 M3 member photo One-many

12 Relationships in QSEE Name –Names the relationship There can be multiple relationships between the same entity types e.g, –Employee –Department »Works in »Is manager of »Has worked in »Must never work in Relationship ends (roles) can be named too Cardinality –from source (start) to destination (end) Optional Identifier –For 1-M, does the source (partly) identify the destination Annotation –Text describing the meaning of this relationship

13

14 Model to target implementation QSEE will produce 3 types of schema –XML document DTD XML schema –SQL Relational Database ORACLE MySQL Microsoft SQL server SQL 2 standard

15 Relational Database target Each entity becomes a table Each attribute becomes a column of a table Each relationship become common fields and values in two tables. –Two cases One-many Many-many

16 One-many relationship Each one-many relationship is implemented by adding the primary key of the entity on the one side (the parent) as new columns on the many (the child) side –So Image gets a new column called ‘blogid’ a foreign key constraint defines the relationship When an image is added to the database, the appropriate value of blogid for the creator is added to the image record (a common value)

17 CREATE TABLE Blogger( blogidINTEGER NOT NULL, nameVARCHAR(20), mobilePhoneNoCHAR(15) UNIQUE, CONSTRAINTpk_Blogger PRIMARY KEY (blogid) ) TYPE=INNODB; CREATE TABLE Image( imageidINTEGER NOT NULL, imageBodyMEDIUMBLOB, titleVARCHAR(100), blogidINTEGER NOT NULL, CONSTRAINTpk_Image PRIMARY KEY (imageid) ) TYPE=INNODB; ALTER TABLE Image ADD INDEX (blogid), ADD CONSTRAINT fk1_Image_to_Blogger FOREIGN KEY(blogid) REFERENCES Blogger(blogid) ON DELETE RESTRICT ON UPDATE RESTRICT;

18 Relationship in RDBMS M1 P4 M1 P5 M1 P1 M1 M2 P3 M2 P7 M2 P7 null M3

19 Using a foreign key To find all the Images belonging to blogger M2 Select * from Image where blogid=‘M2’ To find the creator of photo P1 Select * from image natural join blogger Where imageid=‘P1’

20 Target is XML

21 Target XML Here the names of columns and entities are included in the data. The relationship between blogger and images is containment – all the images for a blogger occur immediately after the details of the blogger herself Same ER model –Different implementations in different technologies.


Download ppt "Data Modelling. EAR model This modelling language allows a very small vocabulary: Just as English has nouns, verbs, adjectives, pronouns.., EAR models."

Similar presentations


Ads by Google