Presentation on theme: "Implementation of the Relational Model"— Presentation transcript:
1Implementation of the Relational Model There is no substitute for the comfort supplied by the utterly taken-for-granted relationship. Iris Murdoch
2Class OutlineWhat are the features of a relational database management system (RDBMS)?What is entity integrity and referential integrity?To what extent are entity and referential integrity supported by MS Access 97?What are the eight algebraic functions supported by a fully relational DBMS? Give examples of each.
3Relational Database Management Systems Relational database architectureCodd, E.F. (1970). A relational model for large shared data banks. CACM, 13(6),based on relational algebra and calculusFirst relational prototype - early 1970s - IBM’s System RRelational databases required considerable computing resources (memory, processing speed)not feasible until mid- 1980s when price-performance ratio droppedlow end (Access, Paradox, dBase, FoxPro, Clipper, R:Base)high end (DB2, Oracle, Sybase, MS SQL Server, Informix, INGRES commercial)relational algebra and relational calculus are logically equivaluent (any query that can be solved in one language can be solved in the other) - relational calculus is more difficult so we’ll concentrate on the algebra
4The Relational Model...consists of relations, which are made up of attributes.A relation is a set of columns (attributes) with values for each attribute such that:Each column (attribute) value must be a single value only.All values for a given column (attribute) must be of the same type.Each column (attribute) name must be unique.The order of columns is insignificantNo two rows (tuples) in a relation can be identical.The order of the rows (tuples) is insignificant.
5Steps to Relational Implementation 1. Define the database structure to the DBMSfor server and mainframe databases, use Data Definition Language (DDL) in a text file that describes columns of tables, defines indexes, constraints and security restrictionsmany PC databases (e.g., MS Access) provide a graphical interface to define the database tablesin both cases, the Database Definition Subsystem of the DBMS creates the indexes and metadata2. Allocation of Media Spaceunnecessary for PC databases, but performance issues must be considered for server/mainframe dbs3. Creating the Database Dataimport pre-existing data or enter data either through DML (Data Manipulation Langauge) or forms of the application
6Relational Data Manipulation Four strategies for relational data manipulation:relational algebra - difficult to use because it is procedural - users must specify not only what they want but how to get itrelational calculus - difficult to learn due to theoretical nature, not used in commercial database processingtransform-oriented languages - non-procedural languages (e.g., SQUARE, SQL, SEQUEL)graphical interface to Data Manipulation Language (DML)query-by-example and query-by-form (behind each is a corresponding SQL query) - supported by many PC RDBMS (Lotus’ Approach, MS Access,Wall Data’s Cyberprise DBApp)application program interface - written in programming languages such as COBOL, Pascal, Perl, C++
7Relational DBMS Defined Logical database model (rather than physical) that represents all data as if they are stored in separate two-dimensional but related tablesEach table consists of single-value data elements describing a common theme among which is one (or more) elements that uniquely describe each record in the table (i.e. no two rows are identical)Tables are related as long as two tables share a common data elementInformation in these tables can be combined on an as-needed basis (flexibility) to get answers to queries and generate complex reports
8Requirements of a RDBMS 1. Enforces Integrity rules(a) Entity Integrity - every row must have a unique identifier (primary key) which cannot include null entries(b) Referential Integrity - foreign key must have either a null entry or an entry that matches the primary key value in a table to which it is relatedParent Table - Table on the one side of a one-to- many relationship.Child Table - Table on the many side of a one-to-many relationship.foreign keyprimary key
9Entity Integrity Elements of a primary key: It must uniquely identify each record n the tableIt must contain unique valuesIt cannot be nullIt cannot be a multi-part fieldIt should contain the minimum number of fields necessary to define uniquenessIt is not optional whole or in partIt must directly identify the value of each field in the tableIts value can only be modified in rare or extreme casesconcatenated primary key
10Referential Integrity Referential integrity is a mechanism that enforces the ties between data in separate tables and prevents them from being brokenReferential integrity minimizes the undesirable likelihood of the existence of a record in the child table for which there is no corresponding record in the parent table - referred to as an orphan (or dangling) recordPrior to setting referential integrity, ensure thatthe field used to tie two tables together (the link field) must be a primary key field in the parent table and a foreign key in the child tablethe link fields have an identical data typethe two tables are in the same database container
11Referential Integrity in Access ’97 A value cannot be entered in the foreign key field of the related table if that value doesn't exist in the primary key of the parent table. A Null value in the foreign key is allowed, specifying that the records are unrelated.A record cannot be deleted from a parent table if matching records exist in a related table.A primary key value in the parent table cannot be changed, if that record has related records.Determined by MS Access on the basis of primary key settings.
12Referential Integrity Options in Access ’97 Cascade UpdateSpecial override of the referential integrity mechanism in order to be able to edit the primary key in the one table; MS Access will automatically make the same change to the foreign key in the child table so the relationship is maintained.Cascade DeleteSpecial override of the referential integrity mechanism to facilitate deleting records in the parent table even when there are related records in the child table. All related records in the child table will automatically be deleted so that there will be no orphan records.Do not use these options unless you realize the full implications of making the selection.
13Relationship Integrity is a way of minimizing data errors MS Access 97 On-line Help
14Requirements of a RDBMS 2. Supports many of the relational algebraic functions - a collection of operations on relations, resulting in relationsSet theory operators:unionintersectdifferenceproductSpecific relational operators:selectprojectdividejoin
15Algebraic function: 1. Union Combination of data without repeating common rows; must have equivalent columns as to number and domains (“union compatible”).Provide information on all employees regardless of their position:Union - Who are all the employees? For newsletter, do not send Anne more than one.Intersection - Who is an Employee AND a Salesperson?note that Anne appears only once even though she’s in both tables
16Algebraic function: 2. Intersection Identification of rows that are common to two relations; must have equivalent columns as to number and domains.Provide information on employees who have both a salesperson and manager role:Union - Who are all the employees? For newsletter, do not send Anne more than one.Intersection - Who is an Employee AND a Salesperson?
17Algebraic Function: 3. Difference Identification of rows that are in one relation and not in another; must have equivalent columns as to number and domains.Provide information on employees who have a salesperson role but do not have a managerial role:Difference: Who is ONLY a salesperson - not a manager?Product: Lists all possible combinations of rows from both tables - not directly used this way but used while trying to accomplish something else
18Algebraic Function: 4. Product Adjoining (concatenating) each row in the first relation to each row in the second relation; must have different column namesNo obvious query; conceptually important because it is used as a building block (Cartesian product) for the join operator.Difference: Who is ONLY a salesperson - not a manager?Product: Lists all possible combinations of rows from both tables - not directly used this way but used while trying to accomplish something else
19Algebraic Function: 5. Select Creation of a relation by identifying only rows that satisfy specific conditionsProvide information on employees who are based in Tokyo:Select: Used a LOT - restricts rows based on a criteria; can combine criteria - ie. whose office is Tokyo and has a salary of at least 2000? (Only Goro Azuma);who is NOT in Brussels? (works somewhere other than in Brussels)Provide information on employees whose salary is at least $2000
20Algebraic Function: 6. Project Creates a relation by deleting columns from an existing relationSelect: Used a LOT - restricts rows based on a criteria; can combine criteria - ie. whose office is Tokyo and has a salary of at least 2000? (Only Goro Azuma);who is NOT in Brussels? (works somewhere other than in Brussels)Provide a list of employee names (not all information):Can “nest” (combine) operators (e.g., select, project)Provide names of employees whose office is in Tokyo:
21Algebraic Function: 7. Divide Creating a new relation by selecting the rows in one relation that match every row in another relationDifference: Who is ONLY a salesperson - not a manager?Product: Lists all possible combinations of rows from both tables - not directly used this way but used while trying to accomplish something elseWho has sold every product?
22Algebraic Function: 8. Join Connection of data across relations: natural join (rows are joined when common columns have equal values); outer join (all rows from both tables even if there is no matching column value) and theta join (not covered)Provide the Supplier Name for each productDifference: Who is ONLY a salesperson - not a manager?Product: Lists all possible combinations of rows from both tables - not directly used this way but used while trying to accomplish something elseProvide all products and all suppliers, joining where possible