Sie sind auf Seite 1von 8

CIS 3810

Spring 2011

Exam 1

Name__________________________

Please answer all questions in the test booklet. You can answer the questions in any order, but start each question on a new page. If a question asks you to explain your answer, you will get very little credit if you do not give an explanation. If it asks for a sentence, give a sentence, not just a word or two.

19 pts I This question deals with the relational algebra. Assume you have two tables, named A and B. Table A has 50 rows and four columns, named e,f,g, and h; table B has 100 rows and three columns, named p, q, and h. Column f in A and column p in B both hold people's names (text); the other columns hold numbers. For parts a-c below, first say whether or not this is a valid relational algebra expression. If it is valid, explain exactly what it does (for example, you could say the command shows the h field for all rows in table A; the result has rows and columns, etc.). If it is not valid, explain why it is not valid. Be precise in your answers. a.
h, p

( h = 15 and q <= 30 (B) ) Show Columns H and P from relation and of rows where H = 15 and Q <= 30 from Table B

b. is intersection f (A) p(B) Not Valid as it doesnt show what type of Join is done on these tables c. is union e, g (A) q >= 15 (B) Not Valid as it doesnt show what type of Join is done on these tables d. Assume we use the join command on the two tables A and B. What is an obvious column(s) to use to join the two tables? Why is this an obvious choice? A THETA JOIN AS IT WILL ONLY SHOW ROWS WHICH ARE RELEVANT TO BOTH TABLES.

e. In 2-3 sentences, describe the result of the join (what fields, how many rows, what will each row look like, etc.). Explain. Be as complete as you can in your answer. It will be fields E,F, G, H, Q

There will only be rows where F exists in both tables. Where F and H are the Primary keys using being concatenated. There will be 4 fields containing numbers while one contact the names of people.

f. In addition to join, what is the name of the other relational algebra command that lets you combine any two tables? (give the name only) Cross Product

g. If you do this other command on the tables A and B shown above, how many rows will the new table have, how many fields, what will each row look like? Explain. Be as complete as you can in your answer. e f g 7 1 17 13 7 2 13 122 17 114 12 140 11 42 21 4 112 140 22 pts II This question refers to using QBE in Access (not using SQL). Above is a display from Microsoft Access of the result of a simple query on a single table named A. You know that table A has fields named e, f, and g, but you dont know what else it has or what the fields represent. You know the primary key of table A is a single field, but you dont know which field is the primary key. a. What can you say about how many rows are in the original table A? What can you say about how many columns? Be complete and explain your answer. There are 6 rows and there are 3 Columns. b. Which column(s) cannot possibly be the primary key of the table A? Be complete and explain your answer. Columns E and G cant be the primary key as they each dont have a distinct set of fields that are non-dupilcative. c. Which column(s) might possibly be the primary key of the table? Be complete and explain your answer. Column f could be the primary key as no field in F is ever repeated.

d. Give the QBE screen for a query that will show columns g, f, and e (appearing in that order) for rows in which f is 7 or g is above 30. The output should be in reverse order of column f. DONT KNOW HOW TO DO THIS WITHOUT ACCESS ON A COMPUTER. WHAT DO YOU MEAN EXACTLY? e. How would you modify part d to do "and" instead of "or" ? (just describe the changes) SAME f. Give a QBE screen for this: Display two columns. One will be the values of field g in this table; the other column will be the sum of the e values for rows containing this g value. Order by g value. SAME

g. Give an IIF expression to do the following: store 10 if the value of x is less than 5; store 100 if the value of x is more than 5; store 20 if the value of x is equal to 5. Do you want this as SQL Statement? h. In Assignment 1, we stored the base pay for each worker as a field in the table. In Assignment 2, we used a query to compute the base pay without storing this value in the table. Give two (number them) reasons why the query method is generally (for most real-world situations) a better method than what we did in Assignment 1.

In assignment 1 we saved the data in our database while in assignment 2 we just computed the data but didnt actually store the data. In real world situations we dont need to update the database by inserting more data to compute something. We can just use the database to compute the data we need to determine. Also most of the time we are only calculating temp data for instance base pay for current work week. We dont need these computed fields after they are calculated as they arent used for updating the database. Just retrieving information from it.

21 pts III SQL Construct a table called S (for SHIRTS) with fields for the name of a person, the age of the person, the color of a shirt that person owns, and the price of the shirt; the age and price are both integers. The fields are called N (for the persons name), A (for the persons age), C (for the shirt's color), and P (for the shirt's price). A person can own more than one shirt, more than one person can own a shirt of certain color, two shirts of the same color can have different prices, but each person can have just one shirt of a certain color (for example John can have only one red shirt). For each part, give one or more SQL commands which will: a. create the table (ignore the primary key constraint) CREATE TABLE S (N char(50), A int, C char(50), P currency) b. insert a row saying Evelyn owns a red shirt that cost 26 and she is 19 years old INSERT INTO S VALUES (Evelyn, 19, Red, 26)

b.

find the name and age of each person who owns a blue shirt that cost between 5 and 10; list in order by the name of the person SELECT S.N, S.A FROM S WHERE C=blue and P >= 5 and P <= 10 ORDER BY N ASC;

c.

find the color of each shirt owned by either Mary or Jed (or by both of them-in that case, list the color two times); list in reverse order of color SELECT S.C FROM S WHERE N=Mary or N=Jed ORDER BY CDesc;

e. find the color of each shirt owned by both Mary and Jed; list in reverse order of color

SELECT S.C

FROM S WHERE N=Mary AND N=Jed ORDER BY C Desc; f. for each color, give the color and the total price of all shirts of that color; order by color SELECT S.C, Count(Price) AS [Total Price of All Shirts] FROM S ORDER BY C ASC; g. determine how many shirts were owned by Bob; print Bob's name and the number SELECT S.N, Count(Color) AS [Number of Shirts Owned] FROM S WHERE S.N =Bob 15 pts IV This question will deal with the table created for question III. a. What are the functional dependencies in this design? (use the letters, A, C, N, P) Do not list trivial ones, but give all the non-trivial ones needed to answer part b. below. C N b. What is the primary key for this table? Give a complete explanation why you picked that and not something else. The color of the shirt and the Name of the Person c. Give one normal form that this design does not satisfy. Explain why it does not satisfy that normal form. 2NF, In order to satisfy 2nd normal form, as not all the non-key attributes are fully functionally dpendenat on the key. For instance Age is not Functionally dependent on Name as Age doesnt uniquely determine Name.

d. When a normal form is not satisfied, the table may suffer from update anomalies. Give two specific update anomalies that can occur in the table. You can show values in the table, but you must also include some words explaining each update anomaly. An Update anomaly can occur if we want to change the name of Bob, to George. An anomaly would occur as it would need to be changed for all the records that appear for bob. Another Update Anomoly can occur we need to change the price of a red shirt owned by Bob, It would update all the red shirts prices and not just the one owned by Bob.

e. What can be done to remove the update anomalies you mentioned in part d? Modify the original design to remove these anomalies. Show the entire new design. Explain why your new design removes the update anomalies. N N C P A C

If we change the name there would be only need to be one change done in each table. If we change the Price owned by one person in a color it would only need to be changed one time. This would prevent any anomalies from occurring.

12 pts V a. Assume you are not in a database system, but you are looking at a printout of the values in a table. If you are looking at the printout, can you be positive, in every case, what the primary key of the table is? If yes, explain how to tell what the primary key is from the values in the printout. Yes you can tell by looking the column(s) that uniquely identifies each row in the table. If no, explain why you cannot tell, and explain how you can determine the primary key. b. If you are in Access, working with a table R, how can you be absolutely positive what the primary key for the table is? Explain exactly what you would do. You would go to the design view of the table and look at which column has a Key logo next to it In Access, is it possible to construct a validation rule for a field Y to say that the only allowed values for the field Yare an integer greater than 10 or the letter K? If it is possible, show how to do it; if it is not possible, explain why it is not possible to do this in a validation rule. It is not possible as a database identifies each column with the data type it should associate it with. Therefore a column cant be a integer or a text but one or the other, this will determine what validate rule to apply it to E.G: text or integers. d. What is the title of our textbook? (give the two names only) Databases Illuminated By Catherine M Ricardo e. What major contributions did Codd make to the field of database systems? Explain your answer in 1-2 sentences. He invented the relational model for database management, and the theoretical basis for relational databases. 11 pts VI a. Is the relational algebra a DBMS? If yes, explain why. If no, explain why it is not a DBMS. Your answer should be two sentences; it is not enough to simply define DBMS. No it is not a DBMS, as the relational algebra is a theoretical lanuge with operators that are applied on one or two relations to produce another relation. While a DBMS is a software package with computer programs that control the creation, maintanice, and use of a database. What is the name of the author of our textbook? d.

b. Is Microsoft Access a DBMS? If yes, explain why. If no, explain why it is not a DBMS. Your answer should be two sentences; it is not enough to simply define DBMS. Yes as it is a software package that has computer programs that allow you to control, maintain, and be able to use the database. Access allows you to control a database by determining its structure. You can maintain it by adding more data or removing data from the database, and you are able to use the database by making QBE or SQL statements within the application. c. Give two specific reasons why the relational model is by far the most popular one in use today. Explain each reason in 1-2 sentences. Most of best DBMS are RDBMS (relational database management system). It is currently being used by Microsoft SQL Server, Microsoft Access, MySQL, Oracle, etc Other models such as the hierachial model and network model use a more explicit representation of relationships. It allows the separation of the conceptual and physical levels, so that conceptual design can be performed without considering storage structures. Data operations are also easy to express, and dont requires users to be familiar with the storage structures used. d. What is the difference between the relational model and ER model? In terms of database design, how are they related to each other? You should have 1-2 sentences for each part. The ER model is an abstract conceptual representation of data where it can be expressed as an enterprise schema. It can be used to then produce a relational database.

Das könnte Ihnen auch gefallen