Southern Methodist University CSE CSE 2337 Introduction to Data Management Chapter 2
Southern Methodist University CSE Overview The Relational Model Relations vs. Tables Queries Query-by-example Relational Algebra
Southern Methodist University CSE 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 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 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 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 SMU Student (StudentID, FirstName, LastName) Professor (FacultyID, FirstName, LastName) Class (ClassNum, Department, FacultyID) Enroll (StudentID, ClassNum, Semester)
Southern Methodist University CSE 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 Premier Products Sample Data
Southern Methodist University CSE Premier Products Sample Data
Southern Methodist University CSE 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 Query Example Find all order numbers for Customer 608 SELECT OrderNum FROM Orders WHERE CustomerNum = 608 SQL
Southern Methodist University CSE 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 Query-By-Example aka QBE Visual/Drag-and-drop approach to writing queries in a RDBMS One of the methods available in MS- Access to write queries
Southern Methodist University CSE The Query Window in Access Execute Query Table Fields
Southern Methodist University CSE 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 Query with Simple Criteria
Southern Methodist University CSE Comparison (Relational) Operators Helps find something other than exact match Relational Operators are: = > < >= <= NOT (not equal to)
Southern Methodist University CSE Query With Comparison Op
Southern Methodist University CSE 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 Query Using AND
Southern Methodist University CSE Query Using OR
Southern Methodist University CSE 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 Query with Computed Fields
Southern Methodist University CSE Query With Computed Field Right-click the column in the Field row and choose Zoom
Southern Methodist University CSE Calculating Statistics Count Sum Avg Max Min StDev Var First Last Built-in statistics (called aggregate functions in Access):
Southern Methodist University CSE Example with Statistics
Southern Methodist University CSE ?