Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Database. Converting Model to target implementation QSEE will produce 3 types of schema –XML document DTD XML schema –SQL Relational Database.

Similar presentations


Presentation on theme: "Relational Database. Converting Model to target implementation QSEE will produce 3 types of schema –XML document DTD XML schema –SQL Relational Database."— Presentation transcript:

1 Relational Database

2

3 Converting 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

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

5 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 Photo gets a new column called ‘memberid’ a foreign key constraint defines the relationship When an image is added to the database, the appropriate value of memberid for the creator is added to the image record (a common value)

6 Relationship in RDBMS M1 P4P5P1 M2 P3 P9 P7 M3 M1 M2null M2

7 Generated SQL DDL CREATE TABLE Member( memberidINTEGER NOT NULL, CONSTRAINTpk_Member PRIMARY KEY (memberid) ) TYPE=INNODB; CREATE TABLE Photo( photoidINTEGER NOT NULL, image64MEDIUMBLOB, memberidINTEGER NOT NULL, CONSTRAINTpk_Photo PRIMARY KEY (photoid) ) TYPE=INNODB;

8 Using a foreign key To find all the Photos belonging to member M2 Select * from photo where memberid=‘M2’ To find the creator of photo P1 Select * from photo natural join member where photoid=‘P1’

9 Foreign Key integrity What happens when you add a Photo –The memberid on the Photo record must reference an existing Member What happens when a member is deleted –Don’t allow it if she has any photos ‘RESTRICT’ –Delete all her photos as well ‘CASCADE’ –Set the memberid to NULL ALTER TABLE Photo ADD INDEX (memberid), ADD CONSTRAINT fk1_Photo_to_Member FOREIGN KEY(memberid) REFERENCES Member(memberid) ON DELETE RESTRICT ON UPDATE RESTRICT;

10 Many-many relationship

11 T1 P4P5P1 T5 P3P7 T2 T1 P1 T2 P1 T1 P4 T5 P4 T2 P5 T1 P7

12 Adding a link table CREATE TABLE Tag( tagNameVARCHAR(40) NOT NULL, CONSTRAINTpk_Tag PRIMARY KEY (tagName) ) TYPE=INNODB; CREATE TABLE Photo_Tag( photoidINTEGER NOT NULL, tagNameVARCHAR(40) NOT NULL, PRIMARY KEY (photoid,tagName), INDEX(photoid), FOREIGN KEY(photoid) REFERENCES Photo(photoid) ON DELETE RESTRICT ON UPDATE RESTRICT, INDEX(tagName), FOREIGN KEY(tagName) REFERENCES Tag(tagName) ON DELETE RESTRICT ON UPDATE RESTRICT ) TYPE=INNODB;

13 Target is XML

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


Download ppt "Relational Database. Converting Model to target implementation QSEE will produce 3 types of schema –XML document DTD XML schema –SQL Relational Database."

Similar presentations


Ads by Google