Presentation is loading. Please wait.

Presentation is loading. Please wait.

R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through.

Similar presentations


Presentation on theme: "R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through."— Presentation transcript:

1 R ELATIONAL D ATA M ODEL Joe Meehean 1

2 R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through shared attributes Attributes columns of the tables Domain allowable values for attributes Tuple single row in a relation 2

3 T ABLES Columns and rows Heading definition of table (column headings) Body content (data rows) Each column has a data type characters, numeric, data, boolean, etc… 3 StdNoLast Name First Name MajorGPA 168732ArnettWillTheatre3.74 654967CrumbRobertArt2.3 579764VogelzangAnnaMusic3.5

4 R ELATIONAL D ATA M ODEL Properties of Relations distinct name each cell contains exactly one value attributes have distinct name values of attribute all from same domain no duplicate tuples (rows) order of attributes unimportant order of tuples unimportant 4

5 R ELATIONAL D ATA M ODEL Relation schema a named relation with attributes domains for attributes Relational database schema set of relation schemas tables that make up database each with own name 5

6 R ELATIONAL K EYS Superkey column or combination of columns containing unique values for each row uniquely identifies a row Candidate key minimal superkey removing any column makes it no longer unique 6

7 R ELATIONAL K EYS Primary key specially designated candidate key each table needs one cannot contain null values called combined or composite if contains multiple columns Foreign key column(s) in which value must match those of candidate key candidate key usually from a different table used to create relationships between tables 7

8 C ONNECTING T ABLES Column values in table match values in another Allows a connection between tables 8 CourseIdDeptNumber 1370CS370 2110Engl110 3270Math270 Offering Id CourseIdSemYear 11111370Fall2011 54122110Spring2012 32123270Summer2012

9 R EPRESENTING R ELATIONAL S CHEMA Name(attr1, attr2, …) College Database Student (StudentID, LastName, FirstName) Faculty (FacultyID, LastName, FirstName) Course (CourseID, DeptID, Number, Name) Offering (CourseID, Section, Sem., Year) Enrolled (StudentID, CourseID, Section) Teaching (FacutlyID, CourseID, Section) 9

10 R ELATIONAL I NTEGRITY Null value a special value indicating absence of actual value value may be unknown or simply not applicable can cause problems 10

11 I NTEGRITY R ULES Helps ensure data isn’t corrupted Entity integrity ensures each tables valid each data row must be unique each table must have at least one candidate key uniquely identifies row in database Referential integrity ensures valid relationships between tables foreign key must reference a real candidate key e.g. each Offering.CourseId must match a Course.CourseId 11

12 F ORMAL I NTEGRITY R ULES Entity Integrity Rule no two rows of a table can contain the same value for the primary key primary key cannot be null Referential Integrity Rule only two kinds of data can be stored in a foreign key a value matching a candidate key a null value 12

13 D ELETE AND U PDATE FOR R EFERENCED R OWS Referenced row row whose primary key is foreign key in another row Changing primary key or deleted referenced row affects the referencing rows what to do Possible actions restrict: do not allow if reference exists cascade: perform same action for referencing rows nullify: replace foreign key with null default: replace foreign key with default 13

14 Q UESTIONS ? 14


Download ppt "R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through."

Similar presentations


Ads by Google