1 / 32

Entity-Relationship Παραδείγματα

Entity-Relationship Παραδείγματα. Πληροφοριακά Συστήματα και Βάσεις Δεδομένων Φροντιστήριο 1 Δαμιανός Χατζηαντωνίου. Επανάληψη. Επανάληψη. Παράδειγμα. Παράδειγμα.

Télécharger la présentation

Entity-Relationship Παραδείγματα

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Entity-Relationship Παραδείγματα Πληροφοριακά Συστήματα και Βάσεις Δεδομένων Φροντιστήριο 1 Δαμιανός Χατζηαντωνίου

  2. Επανάληψη

  3. Επανάληψη

  4. Παράδειγμα

  5. Παράδειγμα Σκεφτείτε μία εφαρμογή πώλησης βιβλίων (π.χ. amazon.com). Θέλουμε να μοντελοποιήσουμε το πρόβλημα αυτό χρησιμοποιώντας το μοντέλο Ο-Σ. • Συγγραφείς βιβλίων (name, address, URL) • Βιβλία (title, year, price, ISBN) • Εκδοτικοί οίκοι (name, address, phone, URL) • Πελάτες (name, address, email, phone) • Αποθήκη βιβλίων (code, address, phone) • Καλάθια αγορών (basketID)

  6. Λύση

  7. Δυαδικές σε Τριαδικές

  8. Κληρονομικότητα

  9. Δημιουργία πίνακα • Δημιουργία του πίνακα Students.Κάθε πεδίο ορίσμου δηλώνεται και επιβάλλεται από το ΣΔΒΔ κάθε φορά που εισάγουμε/ενημερώνουμε μία πλειάδα. • Enrolled πίνακας: κρατάει πληροφορίες για τα μαθήματα ενός φοιτητή. CREATE TABLE Students (sid: CHAR(20), name: CHAR(20), login: CHAR(10), age: INTEGER, gpa: REAL) CREATE TABLE Enrolled (sid: CHAR(20), cid: CHAR(20), grade: CHAR(2))

  10. Εισαγωγή/Διαγραφή • Μπορούμε να εισάγουμε μία πλειάδα: INSERT INTO Students (sid, name, login, age, gpa) VALUES (53688, ‘Smith’, ‘smith@ee’, 18, 3.2) • Διαγραφή πλειάδων που ικανοποιούν μία συνθήκη (e.g., name = Smith): DELETE FROM Students S WHERE S.name = ‘Smith’

  11. Περιορισμοί ακεραιότητας CREATE TABLE Enrolled (sid CHAR(20) cid CHAR(20), grade CHAR(2), PRIMARY KEY (sid,cid) ) • “For a given student and course, there is a single grade.” vs. “Students can take only one course, and receive a single grade for that course; further, no two students in a course receive the same grade.” • Used carelessly, an IC can prevent the storage of database instances that arise in practice! CREATE TABLE Enrolled (sid CHAR(20) cid CHAR(20), grade CHAR(2), PRIMARY KEY (sid), UNIQUE (cid, grade) )

  12. Περιορισμοί ακεραιότητας • Μόνο φοιτητές του πίνακα Students επιτρέπεται να εγγραφούν για μαθήματα. CREATE TABLE Enrolled (sid CHAR(20), cid CHAR(20), grade CHAR(2), PRIMARY KEY (sid,cid), FOREIGN KEY (sid) REFERENCESStudents ) Enrolled Students

  13. Περιορισμοί ακεραιότητας • Θεωρείστε τους πίνακες Students and Enrolled. Το sidστον Enrolled είναι ξένο κλειδί που αναφέρεται στον Students • Τι θα γίνει αν μία γραμμή με ανύπαρκτο student id εισαχθεί στον Enrolled? (Reject it!) • Τι θα γίνει αν μία γραμμή στον Students διαγραφεί? • Also delete all Enrolled tuples that refer to it. • Disallow deletion of a Students tuple that is referred to. • Set sid in Enrolled tuples that refer to it to a default sid. • (In SQL, also: Set sid in Enrolled tuples that refer to it to a special value null, denoting `unknown’ or `inapplicable’.) • Παρόμοια αν το primary key του Students ενημερωθεί

  14. SQL/92 and SQL1999 υποστηρίζουν όλα τα 4 options όταν έχουμε deletes και updates NO ACTION [default] (delete/update is rejected) CASCADE (also delete all tuples that refer to deleted tuple) SET NULL / SET DEFAULT(sets foreign key value of referencing tuple) Περιορισμοί ακεραιότητας CREATE TABLE Enrolled (sid CHAR(20), cid CHAR(20), grade CHAR(2), PRIMARY KEY (sid,cid), FOREIGN KEY (sid) REFERENCESStudents ON DELETE CASCADE ON UPDATE SET DEFAULT )

  15. Άσκηση 3.8 • Emp(eid:integer, ename:string, age:integer, salary: real) • Works(eid: integer, did: integer, pct_time: integer) • Dept(did: integer, dname: string, budget: real, managerid: integer)

  16. Λύση - 1

  17. Λύση - 2

  18. Λύση – 3,4,5

  19. Λύση - 6 DELETE

  20. Άσκηση 3.12 – Λύση

  21. Άσκηση 3.12 - Λύση

  22. Άσκηση 3.12 - Λύση

  23. Άσκηση 3.12 - Λύση

More Related