Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 280: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012.

Similar presentations


Presentation on theme: "CSC 280: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012."— Presentation transcript:

1 CSC 280: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012

2 Lecture 2  Introduction to the Relational Model  Views of Data  Definition of a Relation  Schemas and Keys

3 Different Views of Data  Disk (physical) level:  Where does each bit go on the drive, and how do we retrieve it when we need it?  Logical level:  What is the picture in our head of how the data is arranged?  May or may not differ from reality of the disk level  View level:  That portion of the logical level that we can see  Sometimes a refined version of the logical level

4 What is a Relation?  UNLEARN: In a database context, a relation is NOT a link between two different entities (e.g. a family tree relation)  Though we can represent such data  RE-LEARN: A relation is actually a theoretical collection of potential entities with common attributes  Imagine the data to describe a single instructor  Imagine a relation for instructor as being a data table, but you don’t know what instructors are listed in that table yet Any instructor who ever exists MIGHT be in the table

5 A Relation Instance  Given a Relational Definition:  Instructor(ID, name, dept_name, salary)  We create a data file with actual data:  IMPORTANT: OPERATIONS DEFINED ON RELATIONS WILL BE INDEPENDENT OF ANY ACTUAL DATA

6 In-Class Exercise  Same groups as last time:  Use the relation schema definition format: relation-name(attribute1,attribute2,…) To define at least three relations you might see in a music database

7 Terminology  Relation: a data table with defined column types  Tuple: a single row in a relation table  Attribute: a single column in a relation or tuple  Relation Instance: a data table with specific data entries already in it  Order-Independent: the rows in a relation are not ordered; if the tuples are the same but in different order, the relations are equal.  Domain: indicates the kind of values allowed for an attribute (integer range, characters, date/time, etc)  Should be atomic, or, single-valued

8 Keys  Let K  R  K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(R)  Example: {ID} and {ID,name} are both superkeys of instructor.  Superkey K is a candidate key if K is minimal Example: {ID} is a candidate key for Instructor  One of the candidate keys is selected to be the primary key.  which one?

9 Find the Keys  Determine good primary keys for part of the university schema (underline your choice):  Instructor(ID,name,dept_name,salary)  Department(dept_name,building,budget)  Student(ID,name,dept_name,tot_cred)  Advisor(s_id,i_id)  Takes(ID,course_id,sec_id,semester,year,grade)  Classroom(building,room_number,capacity)  Time_slot(time_slot_id,day,start_time,end_time)

10 Foreign Keys  Foreign key constraint: Value in one relation must appear in another  Referencing relation  Referenced relation

11 Textbook University Schema Diagram

12 In-Class Activity  Draw a schema diagram for the music database from earlier. Underline primary keys, and use arrows for foreign keys.


Download ppt "CSC 280: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012."

Similar presentations


Ads by Google