1 11/3/05CS360 Windows Programming Databases and Data Representation
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 11/3/05CS360 Windows Programming Databases A "relation" is a table of data 1ShereenCS DougCS ChrisCS JoshCS
4 11/3/05CS360 Windows Programming Databases The columns are known as "attributes" 1ShereenCS DougCS ChrisCS JoshCS LectID NameCourse Students
5 11/3/05CS360 Windows Programming Databases The rows are called "tuples" 1ShereenCS DougCS ChrisCS JoshCS LectID NameCourse Students
6 11/3/05CS360 Windows Programming Databases It is allowable for some values to be missing 1ShereenCS DougCS ChrisCS JoshCS LectID NameCourse Students
7 11/3/05CS360 Windows Programming Databases We can add, remove, or update tuples 1ShereenCS DougCS ChrisCS JoshCS MikeCS LectID NameCourse Students
8 11/3/05CS360 Windows Programming Databases Each attribute has an underlying domain, or data type 1ShereenCS DougCS ChrisCS JoshCS MikeCS LectID NameCourse Students int string int
9 11/3/05CS360 Windows Programming Databases The structure of the table is referred to as its schema o Lecturers(LectID, Name, Course, Students) 1ShereenCS DougCS ChrisCS JoshCS MikeCS LectID NameCourseStudents
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 1ShereenCS DougCS ChrisCS JoshCS MikeCS LectID NameCourseStudents
11 11/3/05CS360 Windows Programming Tables Suppose that we want to add data about lecturers offices 1ShereenCS DougCS ChrisCS JoshCS MikeCS NameCourseStudentsLectID
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. 1ShereenCS DougCS ChrisCS JoshCS MikeCS NameCourseStudentsLectIDBuildingRoom
13 11/3/05CS360 Windows Programming Multiple Tables Solution: Add a new table 1ShereenCS DougCS ChrisCS JoshCS MikeCS NameCourseStudentsLectID ShereenStrain203C JoshMarsh324 JoshStrain202 DougStrain201 Building Room
14 11/3/05CS360 Windows Programming Relationships Better to store LectID 1ShereenCS DougCS ChrisCS JoshCS MikeCS NameCourseStudentsLectID 1Strain203C 4Marsh324 4Strain202 2Strain201 Building Room LectID
15 11/3/05CS360 Windows Programming Relationships Better to store LectID 1ShereenCS DougCS ChrisCS JoshCS MikeCS NameCourseStudentsLectID 11Strain203C 24Marsh324 34Strain202 42Strain201 Building Room LectID Foreign key Primary key
16 11/3/05CS360 Windows Programming SQL Queries SELECT returns tuples that satisfy some condition SELECT Name, Course FROM Lecturers WHERE Students > 15 1ShereenCS DougCS ChrisCS JoshCS MikeCS NameCourseStudentsLectID JoshCS MikeCS NameCourse
17 11/3/05CS360 Windows Programming SQL Queries SELECT * FROM Lecturers WHERE Students > 15 Attributes Relations Tuples
18 11/3/05CS360 Windows Programming SQL Queries SELECT * FROM Lecturers WHERE Students > 15 OR Name = ‘Shereen’
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 11/3/05CS360 Windows Programming Database Management Systems Many examples of DBMSs o Oracle o SQL Server o MySQL