Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 11/3/05CS360 Windows Programming Databases and Data Representation.

Similar presentations


Presentation on theme: "1 11/3/05CS360 Windows Programming Databases and Data Representation."— Presentation transcript:

1 1 11/3/05CS360 Windows Programming Databases and Data Representation

2 2 11/3/05CS360 Windows Programming Databases and Data Representation  Database Management System (DBMS)  Provides efficient, convenient, and safe multi- user storage of and access to massive amounts of persistent data  Provides a programming interface that allows a user or program to o - Create new databases and specify their structure o - Query and modify the data  Early DBMSs were ad hoc, with no two the same  Now one approach predominates: relational databases and SQL (Structured Query Language)

3 3 11/3/05CS360 Windows Programming Databases  A "relation" is a table of data 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223

4 4 11/3/05CS360 Windows Programming Databases  The columns are known as "attributes" 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 LectID NameCourse Students

5 5 11/3/05CS360 Windows Programming Databases  The rows are called "tuples" 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 LectID NameCourse Students

6 6 11/3/05CS360 Windows Programming Databases  It is allowable for some values to be missing 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-01 4JoshCS120-0223 LectID NameCourse Students

7 7 11/3/05CS360 Windows Programming Databases  We can add, remove, or update tuples 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 5MikeCS120-0219 LectID NameCourse Students

8 8 11/3/05CS360 Windows Programming Databases  Each attribute has an underlying domain, or data type 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 5MikeCS120-0219 LectID NameCourse Students int string int

9 9 11/3/05CS360 Windows Programming Databases  The structure of the table is referred to as its schema o Lecturers(LectID, Name, Course, Students) 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 5MikeCS120-0219 LectID NameCourseStudents

10 10 11/3/05CS360 Windows Programming Primary Key  Every table must have a primary key o No two tuples can have the same LectID o LectID cannot be null 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 5MikeCS120-0219 LectID NameCourseStudents

11 11 11/3/05CS360 Windows Programming Tables  Suppose that we want to add data about lecturers offices 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 5MikeCS120-0219 NameCourseStudentsLectID

12 12 11/3/05CS360 Windows Programming Tables  But suppose that lecturers can have more than one office.  We can’t add additional rows for the same lecturers without violating the primary key constraint, so we use another table. 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 5MikeCS120-0219 NameCourseStudentsLectIDBuildingRoom

13 13 11/3/05CS360 Windows Programming Multiple Tables  Solution: Add a new table 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 5MikeCS120-0219 NameCourseStudentsLectID ShereenStrain203C JoshMarsh324 JoshStrain202 DougStrain201 Building Room

14 14 11/3/05CS360 Windows Programming Relationships  Better to store LectID 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 5MikeCS120-0219 NameCourseStudentsLectID 1Strain203C 4Marsh324 4Strain202 2Strain201 Building Room LectID

15 15 11/3/05CS360 Windows Programming Relationships  Better to store LectID 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 5MikeCS120-0219 NameCourseStudentsLectID 11Strain203C 24Marsh324 34Strain202 42Strain201 Building Room LectID Foreign key Primary key

16 16 11/3/05CS360 Windows Programming SQL Queries  SELECT returns tuples that satisfy some condition  SELECT Name, Course FROM Lecturers WHERE Students > 15 1ShereenCS360-0112 2DougCS300-0111 3ChrisCS445-0115 4JoshCS120-0223 5MikeCS120-0219 NameCourseStudentsLectID JoshCS120-02 MikeCS120-01 NameCourse

17 17 11/3/05CS360 Windows Programming SQL Queries  SELECT *  FROM Lecturers  WHERE Students > 15 Attributes Relations Tuples

18 18 11/3/05CS360 Windows Programming SQL Queries  SELECT *  FROM Lecturers  WHERE Students > 15  OR Name = ‘Shereen’

19 19 11/3/05CS360 Windows Programming SQL Queries  Wildcards: o % matches any number of characters o _ matches any single character o [] matches any single character in set or range o [^] matches any single character not in set or range

20 20 11/3/05CS360 Windows Programming Database Management Systems  Many examples of DBMSs o Oracle o SQL Server o MySQL  http://dev.mysql.com/


Download ppt "1 11/3/05CS360 Windows Programming Databases and Data Representation."

Similar presentations


Ads by Google