1 Chapter 4 Database Design I: The Entity-Relationship Model.

Slides:



Advertisements
Similar presentations
Chapter 2: Entity-Relationship Model
Advertisements

Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
CSCI 4333 Database Design and Implementation Review for Midterm Exam I
IS698: Database Management Min Song IS NJIT. The Relational Data Model.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
1 Database Design I: The Entity- Relationship Model Chapter 5.
1 Chapter 4 Database Design I: The Entity-Relationship Model.
The Entity-Relationship Model
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Book Chapter 3 (part 2 ) From ER to Relational Model.
The Entity-Relationship (ER) Model
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
The Entity-Relationship Model Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
ENTITY RELATIONSHIP MODELLING
Ch5: ER Diagrams - Part 1 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Text-Book Chapters (7 and 8) Entity-Relationship Model
1 The Entity-Relationship Model Chapter 2. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.) –What are the entities.
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Levels of Abstraction in DBMS data * Schemas are defined using DDL; data is modified/queried using DML. – Views describe how users see data (possibly.
1 Data Modeling Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
1 Database Design I: The Entity-Relationship Model Chapter 5.
CS424 PK, FK, FD Normalization Primary and Foreign Keys Primary and foreign keys are the most basic components on which relational theory is based. Primary.
Chapter 2: Entity-Relationship Model (Continued)
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
Lecture 2: Entity-Relationship Modeling
Chapter 2.  Conceptual design: (ER Model is used at this stage.) ◦ What are the entities and relationships in the enterprise? ◦ What information about.
1 Chapter 4 Database Design I: The Entity-Relationship Model.
1 CSE 480: Database Systems Lecture 5: Relational Data Model.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 1 © Akhilesh Bajaj, 2000, 2002, 2003, 2004.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Entity-Relationship (ER) Modelling ER modelling - Identify entities - Identify relationships - Construct ER diagram - Collect attributes for entities &
Data modeling using the entity-relationship model Chapter 3 Objectives How entities, tuples, attributes and relationships among entities are represented.
Database Management Systems MIT Lesson 02 – Database Design (Entity Relationship Diagram) By S. Sabraz Nawaz.
Entity-Relationship Model
Entity Relationship Diagram (2)
1 Conceptual Design using the Entity- Relationship Model.
Weak Entity Sets A weak entity is an entity that cannot exist in a database unless another type of entity also exists in that database. Weak entity meets.
Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set. – (customer-id, account-number)
Lecture 3 Book Chapter 3 (part 2 ) From ER to Relational.
advanced data modeling
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
ER & Relational: Digging Deeper R &G - Chapters 2 & 3.
LECTURE 1: Entity Relationship MODEL. Think before doing it! Like most of the software projects, you need to think before you do something. Before developing.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module 8: Entity-Relationship.
Chapter 2: Entity-Relationship Model. 3.2 Chapter 2: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts - 6 th Edition Chapter 7: Entity-Relationship Model.
Topic 3: ER – Entity Relationship Model (ERM) 6/12/
IT 5433 LM2 ER & EER Model. Learning Objectives: Explain importance of data modeling Define and use the entity-relationship model Define E/R terms Describe.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
ER Diagrams and Relational Model CS 174a (Winter 2015)
Chapter 2: Entity-Relationship Model
COP Introduction to Database Structures
Database Design Goal: specification of database schema Methodology:
Entity-Relationship Model
Chapter 7: Entity-Relationship Model
Chapter 7 Entity-Relationship Model
Outline of the ER Model By S.Saha
Translation of ER-diagram into Relational Schema
From ER to Relational Model
Module 8 – Database Design Using the E-R Model
Database Modeling using Entity Relationship Model (E-R Model)
Chapter 7: Entity-Relationship Model
Database Management system
Chapter 6b: Database Design Using the E-R Model
Presentation transcript:

1 Chapter 4 Database Design I: The Entity-Relationship Model

2 Database Design Goal: specification of database schema Methodology: E-R model –Use E-R model to get a high-level graphical view of essential components of enterprise and how they are related –Convert E-R diagram to DDL E-R ModelE-R Model: enterprise is viewed as a set of –Entities –Relationships –Relationships among entities

3 Entities EntityEntity: an object that is involved in the enterprise –Ex: John, CSE305 Entity TypeEntity Type: set of similar objects studentscourses –Ex: students, courses AttributeAttribute: describes one aspect of an entity type –Ex: name, maximum enrollment

4 Entity Type Entity type described by set of attributes –Person –Person: Id, Name, Address, Hobbies DomainDomain: possible values of an attribute –Value can be a set (in contrast to relational model) (111111, John, 123 Main St, {stamps, coins}) KeyKey: minimum set of attributes that uniquely identifies an entity (candidate key) Entity SchemaEntity Schema: entity type name, attributes (and associated domain), key constraints

5 Entity Type (con’t) Graphical Representation in E-R diagram: Set valued

6 Relationships RelationshipRelationship: relates two or more entities –John majors in Computer Science Relationship TypeRelationship Type: set of similar relationships –StudentDepartment MajorsIn –Student (entity type) related to Department (entity type) by MajorsIn (relationship type). Distinction: –relation (relational model) - set of tuples –relationship (E-R Model) – describes relationship between entities of an enterprise –Both entity types and relationship types (E-R model) may be represented as relations (in the relational model)

7 Attributes and Roles AttributeAttribute of a relationship type describes the relationship –e.g., John majors in CS since 2000 John and CS are related MajorsIn2000 describes relationship - value of SINCE attribute of MajorsIn relationship type RoleRole of a relationship type names one of the related entities MajorsIn –e.g., John is value of Student role, CS value of Department role of MajorsIn relationship type –(John, CS; 2000) describes a relationship

8 Relationship Type Described by set of attributes and roles MajorsIn –e.g., MajorsIn: Student, Department, Since Student –Here we have used as the role name (Student) the name of the entity type (Student) of the participant in the relationship, but...

9 Roles Problem: relationship can relate elements of same entity type Employee –e.g., ReportsTo relationship type relates two elements of Employee entity type: Bob reports to Mary since 2000 –We do not have distinct names for the roles –It is not clear who reports to whom

10 Roles (con’t) Solution: role name of relationship type need not be same as name of entity type from which participants are drawn ReportsTo – ReportsTo has roles Subordinate and Supervisor and attribute Since Employee –Values of Subordinate and Supervisor both drawn from entity type Employee

11 Schema of a Relationship Type Role namesRole names, R i, and their corresponding entity sets. Roles must be single valued (number of roles = degree of relationship) Attribute namesAttribute names, A j, and their corresponding domains. Attributes may be set valued KeyKey: Minimum set of roles and attributes that uniquely identify a relationship Relationship: –e i is an entity, a value from R i ’s entity set –a j is a set of attribute values with elements from domain of A j

12 Graphical Representation Roles are edges labeled with role names (omitted if role name = name of entity set). Most attributes have been omitted.

13 Entity Type Hierarchies One entity type might be subtype of another –FreshmanStudent –Freshman is a subtype of Student Freshman StudentA relationship exists between a Freshman entity and the corresponding Student entity –e.g., Freshman John is related to Student John IsAThis relationship is called IsA –FreshmanStudent –Freshman IsA Student –The two entities related by IsA are always descriptions of the same real-world object

14 IsA FreshmanSophmoreJuniorSenior Student IsA Represents 4 relationship types

15 Properties of IsA InheritanceInheritance - Attributes of supertype apply to subtype. Student Freshman –E.g., GPA attribute of Student applies to Freshman inherits –Subtype inherits all attributes of supertype. –Key of supertype is key of subtype TransitivityTransitivity - Hierarchy of IsA –StudentPersonFreshman Student, Freshman Student –Student is subtype of Person, Freshman is subtype of Student, so Freshman is also a subtype of Student

16 Advantages of IsA Can create a more concise and readable E-R diagram –Attributes common to different entity sets need not be repeated –They can be grouped in one place as attributes of supertype –Attributes of (sibling) subtypes can be different

17 IsA Hierarchy - Example

18 Constraints on Type Hierarchies Might have associated constraints: –Covering constraint –Covering constraint: Union of subtype entities is equal to set of supertype entities Employee is either a secretary or a technician (or both) –Disjointness constraint –Disjointness constraint: Sets of subtype entities are disjoint from one another FreshmanSophomoreJuniorSeniorFreshman, Sophomore, Junior, Senior are disjoint set

19 Single-role Key Constraint If, for a particular participant entity type, each entity participates in at most one relationship, corresponding role is a key of relationship type WorksIn –E.g., Professor role is unique in WorksIn Representation in E-R diagram: arrow WorksInProfessorDepartment

20 Participation Constraint participation constraintIf every entity participates in at least one relationship, a participation constraint holds: E R ER –A participation constraint of entity type E having role  in relationship type R states that for e in E there is an r in R such that  (r) = e. –e.g., every professor works in at least one department WorksIn ProfessorDepartment Reprsentation in E-R

21 Participation and Key Constraint If every entity participates in exactly one relationship, both a participation and a key constraint hold: –e.g., every professor works in exactly one department WorksIn Professor Department E-R representation: thick line

22 An entity type corresponds to a relation Relation’s attributes = entity type’s attributes –Problem: entity type can have set valued attributes, e.g., Person Person: Id, Name, Address, Hobbies –Solution: Use several rows to represent a single entity (111111, John, 123 Main St, stamps) (111111, John, 123 Main St, coins) –Problems with this solution: Redundancy Key of entity type (Id) not key of relation Hence, the resulting relation must be further transformed (Chapter 6) Representation of Entity Types in the Relational Model

23 Representation of Relationship Types in the Relational Model Typically, a relationship becomes a relation in the relational model Attributes of the corresponding relation are –Attributes of relationship type –For each role, the primary key of the entity type associated with that role Example: S2000Courses – S2000Courses (CrsCode, SectNo, Enroll) Professor – Professor (Id, DeptId, Name) Teaching – Teaching (CrsCode, SecNo, Id, RoomNo, TAs) Teaching S2000CoursesProfessor DeptIdNameRoomNo CrsCodeEnroll SectNo Id TAs

24 Representation of Relationship Types in the Relational Model Candidate key of corresponding table = candidate key of relation –Except when there are set valued attributes Teaching –Example: Teaching (CrsCode, SectNo, Id, RoomNo, TAs) Key of relationship type = (CrsCode, SectNo) Key of relation = (CrsCode, SectNo, TAs) CrsCode SectNo Id RoomNo TAs CSE Hum 22 Joe CSE Hum 22 Mary Set valued

25 Representation in SQL Each role of relationship type produces a foreign key in corresponding relation –Foreign key references table corresponding to entity type from which role values are drawn

26 Example 1WorksIn ProfessorDepartment SinceStatus WorksIn CREATE TABLE WorksIn ( Since DATE, -- attribute Status CHAR (10), -- attribute Professor ProfId INTEGER, -- role (key of Professor) Department DeptId CHAR (4), -- role (key of Department) PRIMARY KEY (ProfId), -- since a professor works in at most one department Professor FOREIGN KEY (ProfId) REFERENCES Professor (Id), Department FOREIGN KEY (DeptId) REFERENCES Department )

27 Example 2Sold ProjectPart DatePrice Sold CREATE TABLE Sold ( Price INTEGER, -- attribute Date DATE, -- attribute ProjId INTEGER, -- role SupplierId INTEGER, -- role PartNumber INTEGER, -- role PRIMARY KEY (ProjId, SupplierId, PartNumber, Date), Project FOREIGN KEY (ProjId) REFERENCES Project, Supplier FOREIGN KEY (SupplierId) REFERENCES Supplier (Id), Part FOREIGN KEY (PartNumber) REFERENCES Part (Number) ) Supplier

28 Representation of Single Role Key Constraints in the Relational Model Relational model representation: key of the relation corresponding to the entity type is key of the relation corresponding to the relationship type ProfessorWorksIn –Id is primary key of Professor; ProfId is key of WorksIn. Professor 4100 does not participate in the relationship. ProfessorWorksIn WorksInProfessor –Cannot use foreign key in Professor to refer to WorksIn since some professors may not work in any dept. (But ProfId is a foreign key in WorksIn that refers to Professor.) CSE 3216 AMS Professor WorksIn Id ProfId WorksInProfessorDepartment Key

29 Representing Type Hierarchies in the Relational Model Supertypes and subtypes can be realized as separate relations –Need a way of identifying subtype entity with its (unique) related supertype entity Choose a candidate key and make it an attribute of all entity types in hierarchy

30 Type Hierarchies and the Relational Model Id attribs1 Id attribs2 Id attribs3 Id attribs4 Id attribs0 Student FreshmanSophmoreJuniorSenior Freshman Sophmore Junior Senior Translated by adding the primary key of supertype to all subtypes. Plus foreign key from subtypes to the supertype. Student FOREIGN KEY Id REFERENCES Student in Freshman, Sophomore, Sunior, Senior

31 Type Hierarchies and the Relational Model Redundancy eliminated if IsA is not disjoint –For individuals who are both employees and students, Name and DOB are stored only once SSN Name DOB SSN Department Salary SSN GPA StartDate 1234 Mary Accounting Person EmployeeStudent Employee Student

32 Type Hierarchies and the Relational Model Other representations are possible in special cases, such as when all subtypes are disjoint See in the book

33 Representing Participation Constraints in the Relational Model Inclusion dependencyInclusion dependency: Every professor works in at least one dep’t. –in the relational model: (easy) ProfessorWorksInProfessor (Id) references WorksIn (ProfId) –in SQL: IfSimple case: If ProfId is a key in WorksIn (i.e., every professor works in exactly one department) then it is easy: WorksIn –FOREIGN KEY Id REFERENCES WorksIn (ProfId) General case – ProfId is not a key in WorksIn, so can’t use foreign key constraint (not so easy): ProfsInDepts CREATE ASSERTION ProfsInDepts CHECK ( NOT EXISTS ( Professor SELECT * FROM Professor P WHERE NOT EXISTS ( WorksIn SELECT * FROM WorksIn W WHERE P.Id = W.ProfId ) ) ) WorksIn ProfessorDepartment Select those professors that do not work

34 Representing Participation Constraint in the Relational Model Professor if ProfId is not a candidate key in WorksInExample (can’t use foreign key in Professor if ProfId is not a candidate key in WorksIn) CSE 1123 AMS 4100 ECO 3216 AMS Professor WorksIn Id ProfId ProfId not a candidate key

35 Representing Participation and Key Constraint in SQL If both participation and key constraints apply, use foreign key constraint in entity table (but beware: if candidate key in entity table is not primary, presence of nulls violates participation constraint). Professor CREATE TABLE Professor ( Id INTEGER, …… PRIMARY KEY (Id), -- Id can’t be null WorksIn FOREIGN KEY (Id) REFERENCES WorksIn (ProfId) --all professors participate ) ProfessorWorksIn Department

36 Participation and Key Constraint in the Relational Model Example: xxxxxx 1123 yyyyyy 4100 zzzzzzz CSE 4100 ECO 3216 AMS Professor Id ProfId WorksIn

37 Participation and Key Constraint in Relational Model (again) Alternative solution if both key and participation constraints apply: merge the tables representing the entity and relationship sets –Since there is a 1-1 and onto relationship between the rows of the entity set and the relationship sets, might as well put all the attributes in one table

38 Participation and Key Constraint in Relational Model Example xxxxxxx 1123 CSE yyyyyyy 4100 ECO zzzzzzzz 3216 AMS Prof_WorksIn Name Id DeptId

39 Entity or Attribute? Sometimes information can be represented as either an entity or an attribute. StudentSemester Course Transcript Grade Student Course Transcript Semester Semester Appropriate if Semester has attributes (next slide)

40 Entity or Relationship?

41 (Non-) Equivalence of Diagrams Transformations between binary and ternary relationships. Sold Project Part Supplier Date Price

ER exercise 1 42 Consider the design of the following database system for managing a conference X: a collection of papers are submitted to X, each of which has a unique paper IDs, a list of authors (names, affiliations, s) in the order of contribution significance, title, abstract, and a PDF file for its content. The conference has a list of program committee (PC) members to review the papers. To ensure review quality, each paper is assigned to 3 PC members for review. To avoid overloading, each PC member is assigned with at most 5 papers, assuming that there are enough PC members. Each review report consists of a report ID, a description of review comment, a final recommendation (accept, reject), and the date the review report is submitted. A PC member can submit at most one review report for the paper that is assigned to him/her.

ER exercise 1 (con’t) 43 Draw an E-R diagram for the above system. Use underlines, thick lines, and arrows to represent constraints. State your assumptions if necessary. Translate the previous E-R diagram for exercise1 into a relational model, i.e., a set of CREAT TABLE statements enforcing all stated constraints. In addition, write a CREATE ASSERTION statement to enforce that no PC member will be assigned to a paper of which she/he is a coauthor.

44 ER Diagram

45 SQL exercise Create table paper ( paperid integer, title VARCHAR(50), abstract VARCHAR(250), pdf VARCHAR(100), primary key (paperid) )

46 SQL exercise Create table author( VARCHAR(100), name VARCHAR(50), affiliation VARCHAR(100), primary key( ) )

CREATE table write( paperid integer, varchar(50), order integer, Primary key(paperid, ), foreign key paperid references paper, foreign key references autor) 47

create table pcmember( VARCHAR(50), name VARCHAR(20), primary key ( ) ) 48

create table review( reportid integer, sdate DATE, comment VARCHAR(250), recommendation CHAR(1), paperid integer, VARCHAR(100), unique(paperid, ), foreign key paperid references paper, foreign key references pcmember) 49

50 CREATE Assertion 3pc CHECK NOT EXISTS( SELECT * FROM Papers P WHERE 3 <> ( SELECT COUNT(*) FROM Review R WHERE R.paperid = P.paperid )

51 CREATE ASSERTION atmostfivepapers CHECK NOT NOT EXISTS ( SELECT * FROM pcmember P WHERE 5 < ( SELECT * FROM review R WHERE R. = P. )

ER exercise 2 Suppose you are asked to design a club database system based on the following information. Each student has a unique student id, a name, and an ; each club has a unique club id, a name, a contact telephone number, and has exactly one student as its president. Each student can serve as a president in at most one of the clubs, although he/she can be the members of several clubs. Clubs organize activities and students can participate in any of them. Each activity is described by a unique activity id, a place, a date, a time and those clubs that organize it. If an activity is organized by more than one club, different clubs might contribute different activity fees. 52

Exercise 2 (con’t) Draw an E-R diagram for the system, in particular, use arrows or thick lines to represent constraints appropriately. Write down your assumptions if necessary. Translate the above E-R diagram to a relational model, in particular, specify your primary key and foreign key constraints clearly. 53

Reference solution 54

CREATE TABLE Student ( studid CHAR(9), VARCHAR(50), name VARCHAR(50) NOT NULL, PRIMARY KEY ( studid ), ) 55

CREATE TABLE Club ( clubid INTEGER, telephone VARCHAR(15), name VARCHAR(50), president CHAR(9) NOT NULL, unique(president), PRIMARY KEY (clubid), FOREIGN KEY (president) REFERENCES Student(studid ) ) 56

CREATE TABLE MemberOf ( clubid INTEGER, studid VARCHAR(50), PRIMARY KEY (clubid, studid ), FOREIGN KEY (clubid ) REFERENCES Club( clubid ), FOREIGN KEY (studid ) REFERENCES Student( studid ) ) 57

58 CREATE TABLE Activities ( actid INTEGER, actdt DATETIME, place VARCHAR(50), PRIMARY KEY (actid ) )

59 CREATE TABLE Organize ( actid INTEGER, clubid INTEGER, fee VARCHAR(50), PRIMARY KEY (actid, clubid ), FOREIGN KEY (actid ) REFERENCES Activities(actid ), FOREIGN KEY (clubid ) REFERENCES Club( clubid ) )

60 CREATE ASSERTION AtLeastOneOrganizer CHECK NOT EXISTS( SELECT * FROM Activities WHERE NOT EXISTS( SELECT * FROM Organize WHERE Organize.actid=Activities.actid )

Exercise 3 Consider the design of a database for the management of grants. Each grant is identified by a unique grant ID, a title, the funding source of the grant, the period (starting data and ending date), and the amount of grant. Each grant might be participated by several professors and each professor might also participate in several grants. Each professor is identified by a unique SSN, name, and address. In addition, several graduate students might be supported by a grant as GRAs, although each student can be supported by at most one grant. Each graduate student has exactly one professor as his/her advisor. 61

Exercise 3 (con’t) 62 Draw an E-R diagram for the system, in particular, use arrows or thick lines to represent constraints appropriately. Write down your assumptions and justifications briefly and clearly. Translate the above E-R diagram into a relational model, i.e., write a set of CREATE TABLE statements. In particular, specify primary key, foreign key and other constraints whenever possible.

Reference solution 63

create table grant( grantid integer, title varchar(50), source varchar(50), periodstart DATE, periodend DATE, amount integer, primary key(grantid) ) 64

Create table professor( ssn char(9), name VARCHAR(20), varchar(20), primary key(ssn), unique( ) ) 65

Create table participate (grantid integer, professorid char(9), primary key(grantid, professorid), foreign key grantid references grant, foreign key professorid references professor(ssn)) 66

Create student (studid integer, name varchar(50), status varchar(20), advisor char(9) NOT NULL, supportgrantid integer, primary key(studid), foreign key advisor references professor, Foreign key supportgrantid references grant(grantid) ) 67

Exercise 4 Consider the design of the following database system: each PhD student has exactly one a dissertation committee which consists of 4-5 faculty, and each committee is for exactly one student. Each student has an ordered list of advisors including the primary advisor followed by 0 or more secondary advisors. Each student has a unique studid, a name, and a major. Each committee has a unique committee id, and the date the committee is formed. Each faculty has a unique facid and a name. Each faculty can participate in multiple committees and be the advisors (either primary or secondary) of several students. 68

Exercise 4 (con’t) Draw an E-R diagram for the above system. Use underlines, thick lines, and arrows to represent constraints. State your assumptions if necessary. Translate your E-R diagram for problem 1 into a relational model, i.e., a set of CREAT TABLE/ASSERTION statements enforcing all stated constraints. In addition, write a CREATE ASSERTION statement to enforce that each committee consists of the primary advisor of the student and all other members of the committee cannot be the secondary advisors of the student. 69

Reference solution 70

Reference solution CREATE TABLE Advise ( order VARCHAR(50), studid VARCHAR(50), facid VARCHAR(50), PRIMARY KEY ( studid, facid ), FOREIGN KEY ( studid ) REFERENCES Students ( studid ), FOREIGN KEY (facid ) REFERENCES Faculty ( facid ) ) 71

CREATE TABLE Student ( studid VARCHAR(50) NOT NULL, name VARCHAR(50), major VARCHAR(50), since DATE, PRIMARY KEY ( studid ) ) 72

CREATE TABLE Participate ( studid VARCHAR(50), facid VARCHAR(50), PRIMARY KEY (studid, facid ), FOREIGN KEY ( studid ) REFERENCES Student FOREIGN KEY (facid ) REFERENCES Faculty ( facid ) ) 73

74 The primary advisor must be in the committee CREATE ASSERTION CHECK NOT EXISTS( SELECT * from Student S WHERE ( SELECT facid // one primary advisor FROM Advise A WHERE A.facid = S.facid and A.order = 1 ) NOT IN ( // all my committee members select facid FROM Participate P WHERE P.stuid = S.studid )

75 Other co-advisors must be NOT in the committee CREATE ASSERTION CHECK NOT EXISTS( SELECT * from Student S WHERE EXISTS( // some committee members are co-advisors SELECT A.facid FROM Advise A, Pariticpate P WHERE s.studid = A.stuid AND A.stuid = P.studid AND A.order <> 1 AND A.facid = P.facid )