Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CSE 2337 Introduction to Data Management Chapter 2 Southern Methodist University CSE 2337 1 Overview • • • • • The Relational Model Relations vs. Tables Queries Query-by-example Relational Algebra Southern Methodist University CSE 2337 2 Relational Database • A relational database is a collection of relations – Each entity has is represented by its own relation – Each attribute is a field or column in that relation – Relationships are common attributes in two or more relations Southern Methodist University CSE 2337 3 Relation • Two dimensional grid in which: – Entries are single-valued – Each column (field or attribute) has a distinct name – All values in a column represent the same attribute – Order of columns and tuples are immaterial – Each tuple is distinct Southern Methodist University CSE 2337 4 In Access (and other DBMSs) • Relation is represented as a table • Attributes are represented as columns in the table • Order of columns rows in the table is immaterial Southern Methodist University CSE 2337 5 Common Notation for Tables • Name of table • List attributes of table in parentheses Rep (RepNum, LastName, FirstName, Street, City, State, Zip, Commission, Rate) Southern Methodist University CSE 2337 6 SMU • Student (StudentID, FirstName, LastName) • Professor (FacultyID, FirstName, LastName) • Class (ClassNum, Department, FacultyID) • Enroll (StudentID, ClassNum, Semester) Southern Methodist University CSE 2337 7 Primary Key • The column or collection of columns that uniquely identifies one row in a table from all other rows in that table. Identify the primary keys in the Premier Products Database. Southern Methodist University CSE 2337 8 Premier Products Sample Data Southern Methodist University CSE 2337 9 Premier Products Sample Data Southern Methodist University CSE 2337 10 Query • A question posed to a DBMS in a form or way in which the DBMS can understand and process the question Southern Methodist University CSE 2337 11 Query Example • Find all order numbers for Customer 608 SELECT OrderNum FROM Orders WHERE CustomerNum = 608 SQL Southern Methodist University CSE 2337 12 SQL • Structured Query Language – Entire computer programming language that allows one to ask simple and sophisticated questions to the DBMS • Based on Relational Algebra Operations • Focus of Chapter 3…… Southern Methodist University CSE 2337 13 Query-By-Example • aka QBE • Visual/Drag-and-drop approach to writing queries in a RDBMS • One of the methods available in MSAccess to write queries Southern Methodist University CSE 2337 14 The Query Window in Access Table Execute Query Fields Southern Methodist University CSE 2337 15 Simple Criteria • Criteria - conditions that data must satisfy • Criterion - a single condition • To display specific query results, enter the condition in the appropriate column in the design grid Southern Methodist University CSE 2337 16 Query with Simple Criteria Southern Methodist University CSE 2337 17 Comparison (Relational) Operators • Helps find something other than exact match • Relational Operators are: = > < >= <= NOT (not equal to) Southern Methodist University CSE 2337 18 Query With Comparison Op Southern Methodist University CSE 2337 19 Compound Criteria • Combines comparison operators • AND / OR used between simple criteria • AND - both criteria must be true • OR - overall criterion is true if either of the individual criteria is true Southern Methodist University CSE 2337 20 Query Using AND Southern Methodist University CSE 2337 21 Query Using OR Southern Methodist University CSE 2337 22 Using Computed Fields • Computed field /attribute is one that can be computed on-the-fly rather than stored in the database • Can be included in queries when needed • Use square brackets if field name contains spaces Southern Methodist University CSE 2337 23 Query with Computed Fields Southern Methodist University CSE 2337 24 Query With Computed Field Right-click the column in the Field row and choose Zoom Southern Methodist University CSE 2337 25 Calculating Statistics • Built-in statistics (called aggregate functions in Access): • Count • StDev • Sum • Var • Avg • First • Max • Last • Min Southern Methodist University CSE 2337 26 Example with Statistics Southern Methodist University CSE 2337 27 Southern Methodist University CSE 2337 28