Catlyn Colson CMPS 342 Midterm October 27, 2009 Part 1: 1. General Terminology a. Database Management System (DBMS): A collection or set of programs that allow creation, maintenance, and use of databases. Allows easy access to database through application programs, easily enforced business rules, multiple user access with controlled data access and security against unauthorized users, data integrity, control of concurrency, protection of software/hardware failure, and maintainability. b. Relational DBMS (RDBMS): The RDBMS was a change of methods for storing and working with large databases, it was a change from the Navigational Model’s method of using linked lists for storage of records which was very inefficient with large databases to using tables of fixed-length records. All records are normalized into specified tables, and then are linked together. This system uses keys to link the data in the database. c. List 3 commonly used DBMS’s: SQL/DS, Microsoft SQL Management, MySQL Administrator, SQLPLUS, ORACLE d. 2-Tier Architecture: Client/Server based in which the client does the processing and queries the database for the data, all application ran on client side. Most used is the logical 2-teir architecture. The client communicates with the server through a standard interface (ODBC). The API allows the client to call the ODBC connection. e. Data Redundancy: With large companies or organizations there can be issues of data redundancy if there is not a good database with a centralized place for data records to be stored. Basically with data redundancy the same data is stored multiple times causing many problems. There are issues when a record is modified. Because of the multiple records of the same data need to be updated, there is more effort and time required by users to make needed changes to the systems and there could be inconsistency between the different locations. Also when there is a large amount of data stored on the databases, the storage space is wasted. 2. Entity- Model a. Describe ER Model: A database modeling method that is used to create a conceptual schema of the database system, and is modeled in an ER Diagram in a top-down manor. It consists of entities (noun) and relationships (verbs) that link two or more entities. Each strong entity has a primary key. b. Why do we need to convert an ER Model into a Relational Model: The main reason it is necessary to convert the ER model into the Relational model is so that it can be implemented directly into the database because most DBMS are based on the relational model. c. Total Participation: All entities in a set must participate in a relationship with another entity. An example of this would be that all employees must belong to a department, it they do not belong to a department in the database then they do not exist. d. Generalization/Specialization: Catlyn Colson CMPS 342 Midterm October 27, 2009 Defining a more generic entity that can be linked to a set of more specialized entities. Generalization uses a bottom-up method, whereas specializations uses a top-down method. Consists of subclasses and superclasses. An of specializations is employee, in which they must be a secretary/tech/engineer, they have a manager, and the employee is a salaried employee/hourly employee. The employee would be the superclass and all the below entities would be subclasses. e. Union: A union joins multiple superclasses to a subclass. An example of this would be vehicle registration, in which a registered vehicle has an owner. The owner could be a person but not all people own a vehicle, or it could be a bank or company. This is an example of partial participation, not all superclasses must belong to a subset. 3. Relational Model a. What is a relational model: The relational model was designed by Codd in the late 60’s and is based on predicate logic. It allows the use of queries. All data can be represented through mathematical relations. Relational calculus and algebra are used to query the data on the database. b. What is a relation schema: A relation schema is used to describe a relation. The Relation schema (R) is denoted by R(A1, A2, …, An) in which A is an attribute. c. What is a relation instance: An instance in which there is a relation between two entities. An example of this would be entities employee and department, relationship set works_for, and a relation instance would be the case a specific employee (e1) has a corresponding relation with the department (d1) with the relation (r1). d. What is a candidate key: A candidate key is a collection of attributes of an entity that can uniquely identify a record. Typically one of the candidate keys is used as a primary key. An example of a candidate key would be the license plate and vin number on a vehicle, both are candidate keys for the vehicle entity. e. What is a primary key: A candidate key that is used to identify each row in a table. Because it is a candidate key it must be unique to that entity. Some example of this would be ID numbers, social security numbers, etc. 4. From ER/EER to Relational Model a. Why do we have to convert ER database into a relational database: It is necessary to convert the ER database into a relational database because the DBMS us a relational database method. b. How to convert a weak entity set to a relation: To convert a weak entity set to a relation it is necessary to make a connection or link between the weak entities to their dominate entity. To do this the weak entity will use an inherited primary key from the dominate entity. c. List all 3 approaches that can be used to convert a 1:1 binary relationship into a relation: The foreign key approach, merged relation approach, and cross reference approach. d. List all 4 approaches to convert super class and subclasses into relation(s): Multiple relations - Superclass and subclass used for specialization. Multiple relations – Subclass relations only in which specialization is overlapping, the entity is duplicated. Catlyn Colson CMPS 342 Midterm October 27, 2009 Single relation with one attribute, in which one for subclass with multiple flags overlapped. Single relation with multiple type attributes, in which one for subclass with one single flag. Part 2: 1. Find items sold by at least two different departments: Relational Algebra: S1 s2 π [σ (sell sell) ] item.* s1.iname = s2.iname s1.dname != s2.dname Tuple Relational Calculus: { i.iname | item(i) (∃s1)( ∃s2)(sell(s1) sell(s2)) s1.dname!= s2.dname s1.iname=i.iname } Domain Relational Calculus: { <i,-,-,-> | item<i,-,-,-> sell(i,dn) s1.iname = s2.iname sell(i,!=dn) } 2. Find suppliers who supply something to a department on the second floor: Relational Algebra: S d π [σ (supply dept) ] s.* s.dname=d.dname d.floor=’2’ Tuple Relational Calculus: { s | supply(s) (∃d)department(d) s.dname=d.dname d.floor=’2’ } Domain Relational Calculus: { <s,-,d> | supply<s,-,d> dept(d,-,2) } 3. Find the department(s) that sell the most expensive item(s): Relational Algebra: i1 i2 s1 s2 π [σ (item item sell sell) ] s1.dname i1.price>i2.price s1.dname!=s2.dname i1.iname=s1.iname i2.iname=i2.iname Tuple Relational Calculus: { s1.dname | sell(s1) (∃s2)(∃i1)(∃i2) (sell(s2) item(i1) item(i2)) s1.dname!=s2.dname i1.price>i2.price i1.iname=s1.iname i2.iname=s2.iname } Domain Relational Calculus: { <-,d> | sell<i1,d> sell(i2,!=d) item(i1,-,p,-) item(i2,-,<p,-) } 4. Find the departments that sell all items from the supplier named “Kids’ Toy”: Relational Algebra: S1 s2 π [σ (sell X supply) ] Catlyn Colson CMPS 342 Midterm October 27, 2009 s1.dname s1.dname=s2.dname s1.sname=”Kids’ Toy” s1.iname=s2.iname Tuple Relational Calculus: { s1.dname | sell(s1) (∃s2)supply(s2) s1.sname=”Kids’ Toy” } s1.dname =s2.dname s1.iname=s2.iname Domain Relational Calculus: { <d,-> | sell<d,i> supply(“Kids’ Toy”, i, d) } 5. Find all items but the most expensive and least expensive ones: Relational Algebra: Tuple Relational Calculus: Domain Relational Calculus: 6. List suppliers who supply at least one item to each of the departments on the 2nd floor: Relational Algebra: d s π [σ (dept X supply) ] s.sname d.dname=s.dname d.floor=’2’ Tuple Relational Calculus/Domain Relational Calculus: { <s,-,-> | supply<s,-,d> dept(d,-,2) } 7. List departments who sell no blue color items: Relational Algebra: d s i π [σ (dept X sell X item) ] dept.* d.dname=s.dname s.iname=i.iname i.color!=’blue’ Tuple/Domain Relational Calculus: { <d,-,-> | dept(d,-,-) sell(d,i) item(i,!=blue,-,-) } 8. List departments which sell only items that are more expensive than each item sold on the 1st floor (Domain Relational Calculus): Select highest item sold on first floor (HI): { <in,-,-p1,-> | item<in,-, p1,-> AND (Ei2)(Es1)(Es2)(Ed1) item(i2,-,<p1,-) AND dept(dn,-,1) AND Sell(dn,i1) AND sell(dn,i2) } Select departments that sells only items higher than (HI): { <dn2,-,f2> | dept(dn2,-,f2!=1> AND (Ei)(Es) item(i, -,p>HI,-) AND sell(dn2, i) }