Download presentation
Presentation is loading. Please wait.
Published byClaire Edwards Modified over 9 years ago
1
Discussion #22 1/10 Discussion #22 Relational Data Model
2
Discussion #22 2/10 Topics Databases Relational database Relations and schemas –Keys –Tuples and predicates
3
Discussion #22 3/10 Database A persistent collection of information about various kinds of objects (persons, places, things, events). Each object or entity can be characterized by a set of attributes or properties from a domain. e.g.person(SSN, Name, Address, Phone) Each individual object has a value associated with it for each attribute; this is a tuple and forms a record. e.g.SSN: 123-45-6789 Name:Pat Carter Address:12 Main Phone:555-5555. A set of records is a file (relation, for a relational database). A collection of files is a database (relations or tables, for a relational database). Typical operations on a database: –insert– data retrieval –delete– summarize data (e.g. averages, totals, mins, …) –update– create/delete files A database system helps people manage databases. –data storage –integrity / security –crash recovery
4
Discussion #22 4/10 StudentIDNameAddressPhone 12345C. Brown12 Apple St.555-1234 67890L. Van Pelt34 Pear Ave.555-5678 22222P. Patty56 Grape Blvd.555-9999 33333Snoopy12 Apple St.555-1234 CourseStudentIDGrade CS10112345A CS10167890B EE20012345C EE20022222B+ EE20033333B CS10133333A- PH10067890C+ CourseDayHour CS101M9AM CS101W9AM CS101F9AM EE200Tu10AM EE200W1PM EE200Th10AM PH100Tu11AM CoursePrerequisite CS101CS100 EE200EE005 EE200CS100 CS120CS101 CS121CS120 CS205CS101 CS206CS121 CS206CS205 CourseRoom CS101Turing Aud. EE20025 Ohm Hall PH100Newton Lab. Relational Database Example snapcr cdhcsg cp
5
Discussion #22 5/10 Relational Schemas Each relation has a schema –name –set of attributes –domain for each attribute Example: –Names: snap, cp, cdh, cr, csg –Attributes:table headers –Domains:studentID: integer all the rest are strings, but we could be more specific (e.g. time, day, grade)
6
Discussion #22 6/10 Relational Tables Table tuples are n-tuples, where n is the arity or degree of the relation (i.e. the number of attributes). Each n-tuple t D 1 D 2 … D n, where the D i ’s are the domains. e.g. a 3-tuple t of cdh is an element string string string or string day time or course day time depending on how specific we make our domains. A table is a set of tuples, all with the same schema e.g. cdh D course D day D hour
7
Discussion #22 7/10 Tuple Sets (Relations, Tables) & Keys Because a table is a set of tuples, there are no duplicates. Thus, there is always a set of attributes whose values uniquely identify a tuple (even if it is all of them). A set of attributes whose values always uniquely identify a tuple constitutes a key. Typically, one or two attributes make up a key. Keys must be declared we cannot assume uniqueness. e.g. Name is not a key there could be another C. Brown Some systems add a tuple identifier as the key.
8
Discussion #22 8/10 Keys Examples TableKey snapStudentID Name, Address, Phone (possible key?) cpCourse Prerequisite cdhCourse Day Hour Can a course meet twice on the same day? If not:Course Day crCourse Room Does a course always meet in the same room? If so:Course csgCourse StudentID
9
Discussion #22 9/10 Predicates and Tuples A table name for tuples of arity n is an n-place predicate. –cdh('CS101','M','9AM') –Asserts that CS101 meets on Monday at 9:00 am. Predicates give each tuple a meaning in the ordinary sense of predicates. –The subset of D 1 D 2 … D n present in the database are those assigned T; all others are assigned F. (Closed-World Assumption) –Interpretation: Domain For each predicate and every substitution, T or F.
10
Discussion #22 10/10 Database Tuples Database tuples (strictly speaking) are not true subsets of D 1 D 2 … D n because we can alter the column order if we do so “correctly.” More properly defined, a tuple in a relation is a set of attribute-value pairs. –e.g. {(Course, 'CS101'), (Day, 'M'), (Hour, '9AM') } = {(Day, ' M ' ), (Course, ' CS101 ' ), (Hour, ' 9AM ' ) } –Normally, we factor out the attribute and fix the order. –Implication: we can interchange columns. cr = Course Room =RoomCourse CS101 Turing Aud.Turing Aud.CS101 EE200 25 Ohm Hall25 Ohm HallEE200 PH100 Newton Lab.Newton Lab.PH100
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.