200 likes | 321 Views
Databases and Data Representation. 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
E N D
Databases and Data Representation CS360 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 • - Create new databases and specify their structure • - 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) CS360 Windows Programming
Databases • A "relation" is a table of data CS360 Windows Programming
Databases • The columns are known as "attributes" Students LectID Name Course CS360 Windows Programming
Databases • The rows are called "tuples" Students LectID Name Course CS360 Windows Programming
Databases • It is allowable for some values to be missing Students LectID Name Course CS360 Windows Programming
Databases • We can add, remove, or update tuples Students LectID Name Course CS360 Windows Programming
Databases • Each attribute has an underlying domain, or data type Students LectID Name Course int string string int CS360 Windows Programming
Databases • The structure of the table is referred to as its schema • Lecturers(LectID, Name, Course, Students) LectID Name Course Students CS360 Windows Programming
Primary Key • Every table must have a primary key • No two tuples can have the same LectID • LectID cannot be null LectID Name Course Students CS360 Windows Programming
Tables • Suppose that we want to add data about lecturers offices LectID Name Course Students CS360 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. LectID Name Course Students Building Room CS360 Windows Programming
Multiple Tables • Solution: Add a new table LectID Name Course Students Building Room CS360 Windows Programming
Relationships • Better to store LectID LectID Name Course Students LectID Building Room CS360 Windows Programming
Relationships • Better to store LectID LectID Name Course Students LectID Building Room Primary key Foreign key CS360 Windows Programming
SQL Queries • SELECT returns tuples that satisfy some condition • SELECT Name, Course FROM Lecturers WHERE Students > 15 LectID Name Course Students Name Course CS360 Windows Programming
SQL Queries • SELECT * • FROM Lecturers • WHERE Students > 15 Attributes Relations Tuples CS360 Windows Programming
SQL Queries • SELECT * • FROM Lecturers • WHERE Students > 15 • OR Name = ‘Shereen’ CS360 Windows Programming
SQL Queries • Wildcards: • % matches any number of characters • _ matches any single character • [] matches any single character in set or range • [^] matches any single character not in set or range CS360 Windows Programming
Database Management Systems • Many examples of DBMSs • Oracle • SQL Server • MySQL • http://dev.mysql.com/ CS360 Windows Programming