Download presentation
Presentation is loading. Please wait.
Published byHarriet Bryant Modified over 9 years ago
1
12/2/2015CPSC-4360-01, CPSC-5360-01, Lecture 41 Relational Model
2
12/2/2015 CPSC-4360-01, CPSC-5360-01, Lecture 4 2 Introduction The Relational Database Management System (RDBMS) has become the dominant DBMS in use today. All data are logically structured withing relations (tables). Based on the relational data model proposedby Dr E.F. Codd. Design methology will be based on the relational model
3
What is a data model ? Data model : Integrated collection of concepts for describing data (data requirements). A data model may comprise 3 componants : A structural part ( rules on how database to be constructed) Manipulative part (Type of operations allowed on the data) Set of integrity rules ( to ensure data accuracy) 12/2/2015 CPSC-4360-01, CPSC-5360-01, Lecture 4 3
4
Terminilogy In the relational model, we use relations ( tables ) to hold info about the objects that we want to represent in the database. Relation : Table with column and rows Attribute : named column of a relation Domain : set of allowable (possible)values for one or more attributes. Tuple : a record of a relation (row in the table) Relational Database - collection of normalized relations with distinct relation names. 12/2/2015 CPSC-4360-01, CPSC-5360-01, Lecture 4 4
5
12/2/2015 CPSC-4360-01, CPSC-5360-01, Lecture 4 5
6
Examples of domain for attributtes 12/2/2015 CPSC-4360-01, CPSC-5360-01, Lecture 4 6
7
© Pearson Education Limited, 2004 7 Properties of Relations Table name is distinct from all other table names in the database. Each cell of table contains exactly one atomic (single) value. Each column has a distinct name. Values of a column are all from the same domain. Each record is distinct (no duplicate record) Order of columns has no significance. Order of records has no significance, theoretically (affect efficiency of accessing records )
8
© Pearson Education Limited, 2004 8 Relational Keys Superkey A column, or a set of columns (minimum number), that uniquely identifies a record within a table. Candidate Key “K” Uniqueness : value uniquely identify that record. Irreducibility : No proper subset of K has the uniqueness property Each record in a table must be unique, so we need a mean to provide this uniqueness.
9
12/2/2015 CPSC-4360-01, CPSC-5360-01, Lecture 4 9 “ city” cannot be selected as a candidate key for the Branch table. Why? What about “zipCode”? “ Branch ” table
10
Composite key Role table represents the name of the character played by an actor in videos. 12/2/2015 CPSC-4360-01, CPSC-5360-01, Lecture 4 10
11
© Pearson Education Limited, 2004 11 Relational Keys Primary Key Candidate key selected to identify records uniquely within table. Alternate Keys Candidate keys that are not selected to be primary key. Example : for Branch table, if “branchNo” is the primary key then “zipCode” is the alternate key.
12
© Pearson Education Limited, 2004 12 Relational Keys Foreign Key Column, or set of columns, within one table that matches candidate key of some (possibly same) table. Note: When a column appears in more than one table, its appearance usually represents a relationship between records of the two tables
13
© Pearson Education Limited, 2004 13 Relational Integrity Every column has an associated domain (constraint the value that a column can take). There are 2 more important integrity rules that apply to all instances of the database: Entity integrity Referential integrity
14
© Pearson Education Limited, 2004 14 Relational Integrity Null Represents value for a column that is currently unknown or not applicable for record. Deals with incomplete or exceptional data. Represents the absence of a value and is not the same as zero or spaces, which are values.
15
© Pearson Education Limited, 2004 15 Relational Integrity Entity Integrity In a base table, no column of a primary key can be null. Referential Integrity If FK exists in a table, either FK value must match a candidate key value of some record in its home table or FK value must be wholly null.
16
© Pearson Education Limited, 2004 16 Relational Integrity Business Rules Rules that define or constrain some aspect of the organization. Example : a member can only rent a maximum of 10 videos at any one time.
17
© Pearson Education Limited, 2004 17 Relational Languages Two main languages: SQL (Structured Query Language), standardized by ISO. QBE (Query-by-Example), alternative graphical “point-and-click” way of querying database.
18
Schema Diagram
19
Relational Database Keys Table 2.3
20
Figure 2.4 An Illustration of Integrity Rules
21
An Example Table Students (sid: string, name: string, login: string, age: integer, gpa: real) sidnameloginagegpa 50000Davedave@cs193.3 53666Jonesjones@cs183.4 53688Smithsmith@ee183.2 53650Smithsmith@math193.8 53831Madayanmadayan@music111.8 53832Gulduguldu@music122.0
22
Another example: Courses Courses (cid, instructor, quarter, dept) cidinstructorquarterdept Carnatic101JaneFall 06Music Reggae203BobSummer 06Music Topology101MarySpring 06Math History105AliceFall 06History
23
Keys Primary key – minimal subset of fields that is unique identifier for a tuple sid is primary key for Students cid is primary key for Courses Foreign key –connections between tables Courses (cid, instructor, quarter, dept) Students (sid, name, login, age, gpa) How do we express which students take each course?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.