The Database Approach u Emphasizes the integration of data across the organization
Components of Relational Model u Data structure: Represented in the form of tables with rows and columns u Data manipulation: Powerful operations (SQL) used to manipulate data stored in relations u Data integrity: Facilities are included to specify business rules that maintain the integrity of data when they are manipulated.
Relation u A named two-dimensional table of data. Each relation consists of a finite set of named columns and an arbitrary number of unnamed rows. Notation: RELATION NAME(Attribute1, Attribute2…) Example: EMPLOYEE(EmpID, Name, Dept, Salary)
Properties of Relations u Each relation (or table) has a unique name u Entries in columns are atomic (no repeating groups - single valued) u Entries in columns are from the same domain u Each row is unique (no duplicate rows) u The sequence of columns (left to right) is insignificant u The sequence of rows (top to bottom) is insignificant
Relational Keys u Allow storage and retrieval of a row of data based on stored values of that data u Primary Key: An attribute (or combination of attributes) that uniquely identify each row in a relation u Composite Key: A primary key that consists of more than one attribute
Foreign Key u An attribute in one table that is a primary key in another table. Purchase Order PO Date Vendor #Item # NameAddressBalance Vendor NameQOH Reord- Pt. Item PO # Vendor # Item # Foreign Keys
Integrity Constraints u Facilitate maintaining accurate data –Domain Constraints: the set of values that may be assigned to an attribute must be from the same domain »Domain name, meaning, data type, size/length, allowable values or ranges –Operational Constraints
Integrity Constraints –Entity Integrity: Every relation must have a primary key and the data values of that key are valid. »The primary key can never be null –Referential Integrity: Either each foreign key value must match a primary key value in the other relation or the foreign key value must be null
Referential Integrity Constraints Customer-ID Customer-Name Customer-Address Order-ID Order-Date Customer-ID Order-ID Product-ID Quantity Product-ID Product-Description Product-Finish Unit-Price On-Hand CUSTOMER ORDER ORDER LINE PRODUCT
Well Structured Relations u Minimum Redundancy u Users can insert, modify and delete row (instances) without errors or inconsistencies (Anomalies). –Anomalies: errors that may result when a user attempts to update a table that contains redundant data.
Anomalies u Insertion Anomaly u Deletion Anomaly u Modification or Update Anomaly
Sample Relation u Std_IDCrse_IDAddressCourse Grade First St.Psych B Second St.Psych A Third St.History C Fourth St.Physics A Fifth St.History B First St.Physics C Second St.History A
Insertion Anomaly Consider the relation on previous slide ENROLL(Std_ID, Crse_ID, Address, Grade) To add a new student you must supply both Std_ID and Crse_ID. This is an anomaly because the user should be able to insert a new student without supplying course data
Delete and Modification Anomalies u Deletion: If a particular student is deleted additional information about the courses taken are also lost u Modification: If the student’s address changes, the information must be entered in numerous rows
Another example of Anomalies Consider the relation SALES(Cust_ID,Name,Salesperson, Region) u Insertion: a new salesperson assigned to the north region cannot be entered until a customer is assigned u Deletion: if a customer is deleted so is info telling what region a salesperson is assigned u Modification: if a salesperson is reassigned to another region several rows need to be updated
What is the solution for these anomalies? Normalization Create Normalized Relations OR Create Well-Structured Relations