25
The short answer questions will be spot checked and graded for completion, but not checked for accuracy. I encourage you to form a study group; get together to prepare for exams. Once your homework and labs are graded and returned, I encourage you to compare answers others in your study group who have also had the lab, or homework, graded and returned. You may not share this work outside the class; it is a violation of academic integrity to share your work with others outside the class. It is a violation of academic integrity to receive the software engineering work completed by other students. If there are short answer questions, you must answer at least 90% of these questions correctly! I/We realize that the penalty for turning in work that is not my own, or assisting others in doing so, can range from an "F" in the class to dismissal from Trinity University. Print Name ____________________________________________ Time Required = ______.____ Hrs. Signature/Pledge ______________________________________________________________________ MySQL #2 Lab Individual/Duo Lab 30 Points In a Duo Lab, Two Class Members May Sit Side By Side And Work Through The Lab On Two Different Computers You May Choose To Help Each Other! You May Share Techniques! You May Show You’re your Team Mate Your Code But Each Person Is To Do All Of Their Own Typing & Enter All Of Their Own Command. Each Person Is To Sign/Pledge & Submit Their Own Pledge Form. You May Enter Your Solutions Into The Word Document & Print If Doing This Lab Individually! 5% Extra Credit If You Register https://lagunita.stanford.edu/courses/Home/Databases/ Engineering/about Select the Self-Paced Database Mini-Courses 1] _______________ {Initial/Pledge} I have registered for the Stanford Database Course. 5% Extra Credit If You Watch The Optional Video On Relational Algebra I 1] _______________ {Initial/Pledge} I have registered for the Optional Video on Relational Algebra (linked at the end of this lab). DB-Queries – REVIEW FROM CSCI-2320 AANSWER ALL SQL QUESTIONS USING MySQL – Don't Forget The Semicolons At The End Of Statements! Hand write these solutions Use MySQL Workbench To Import Library2.sql

DESIGN GOALScarme.cs.trinity.edu/.../3343/Labs/MySQL-2-Intro-To-Databases-HW.docx  · Web viewMySQL-2-HW.docx ... The Word Document & Print If ... this is going to get if we want

  • Upload
    vutuyen

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

The short answer questions will be spot checked and graded for completion, but not checked for accuracy. I encourage you to form a study group; get together to prepare for exams. Once your homework and labs are graded and returned, I encourage you to compare answers others in your study group who have also had the lab, or homework, graded and returned. You may not share this work outside the class; it is a violation of academic integrity to share your work with others outside the class. It is a violation of academic integrity to receive the software engineering work completed by other students. If there are short answer questions, you must answer at least 90% of these questions correctly!

I/We realize that the penalty for turning in work that is not my own, or assisting others in doing so, can range from an "F" in the class to dismissal from Trinity University.

 Print Name  ____________________________________________    Time Required = ______.____ Hrs.

Signature/Pledge   ______________________________________________________________________

MySQL #2 Lab

Individual/Duo Lab30 Points

In a Duo Lab, Two Class Members May Sit Side By Side And Work Through The Lab On Two Different Computers You May Choose To Help Each Other! You May Share Techniques! You May Show You’re your Team Mate Your Code But Each Person Is To Do All Of Their Own Typing & Enter All Of Their Own Command. Each Person Is To Sign/Pledge & Submit Their Own Pledge Form.

You May Enter Your Solutions Into The Word Document & Print If Doing This Lab Individually!

5% Extra Credit If You Register

https://lagunita.stanford.edu/courses/Home/Databases/Engineering/about Select the Self-Paced Database Mini-Courses

1] _______________ {Initial/Pledge} I have registered for the Stanford Database Course.

5% Extra Credit If You Watch The Optional Video On Relational Algebra I

1] _______________ {Initial/Pledge} I have registered for the Optional Video on Relational Algebra (linked at the end of this lab).

DB-Queries – REVIEW FROM CSCI-2320

AANSWER ALL SQL QUESTIONS USING MySQL – Don't Forget The Semicolons At The End Of Statements!

Hand write these solutions

Use MySQL Workbench To Import Library2.sql

Table Library2.Books

MySQL-2-HW.docx CSCI-3343 2 | P a g e

Table Library2.Users

ASCII CHAR

1] ___________________________________________________________________________________ Write the output from the following query:SELECT ASCII('A'), ASCII('C'), CHAR(65), CHAR(67);

FLOOR

1] ___________________________________________________________________________________ Write the output from the following query:SELECT FLOOR(12.3), FLOOR(12.49), FLOOR(12.5), FLOOR(12.51), FLOOR(12.9)

CEILING

1] ___________________________________________________________________________________ Write the output from the following query:SELECT CEILING (12.3), CEILING (12.49), CEILING (12.5), CEILING (12.51), CEILING (12.9)

MySQL-2-HW.docx CSCI-3343 3 | P a g e

RAND

1] Rand returns a random number that is in the range _______ <= X < _______

2] ___________________________________________________________________________________ Write a query that returns a random number in the range 1 to 5

3] ___________________________________________________________________________________ Write a query that returns a random number in the range 1 to 100

4] ___________________________________________________________________________________ Write a query that returns a random number in the range 10 to 20

5] ___________________________________________________________________________________ Write a query that returns a random number in the range -3 to +3

6-8] Write a query that replaces the Phone of all of the Users with some random value in the range (210) 999-0000 to (210) 999-9999

9-11] Write a query that replaces the Passwd of all of the Users with some random 5 character value in the range AAAAA to ZZZZZ

MID SUBSTRING

1] ___________________________________________________________________________________ Write the results from executing the query below:SELECT MID("Trinity", 4, 2)

MySQL-2-HW.docx CSCI-3343 4 | P a g e

2] ___________________________________________________________________________________ Write the results from executing the query below:SELECT MID("UNIVERSITY", 5, 3)

3] Write a query that displays the fourth & fifth letters of the Last names of all Users. Do Not Use Substring

4] Write a query that displays the fourth & fifth letters of the Last names of all Users. Do Not Use Mid

DELETE

1] Write a query that deletes all of the records in the University Table. Hint: There Is No *

2] Write the MySQL command which will delete the University whose ID is 10.

3] Write the MySQL command which will delete all of the Universities whose ID is an even number.

4] How do you undelete a record?

_____________________________________________________________________________

_____________________________________________________________________________

MySQL-2-HW.docx CSCI-3343 5 | P a g e

SUM

1] If you were to buy one copy of each of the books, what would it cost? Write the query for the calculation.

2] If you were to add all of the User ID's, what would be the total? Write the query for the calculation.

MIN

1] Write the query that would reveal the cost of the least expensive book.

2] Write the query that would reveal the lowest User ID.

3] Write the query that would reveal all of the information about the least expensive book(s).

MySQL-2-HW.docx CSCI-3343 6 | P a g e

MAX

1] Write the query that would reveal the cost of the most expensive book.

2] Write the query that would reveal the lowest User ID.

3] Write the query that would reveal all of the information about the most expensive book(s).

Filling A Variable/Alias

1] Write a query that displays all information of the about those Users whose Last name begins with an H.

2] Write a query that fills a variable, called NoH, with the number of Users whose Last name begins with and H.

MySQL-2-HW.docx CSCI-3343 7 | P a g e

3] Write the query that fills a variable, called MaxPrice, with the cost of the most expensive book.

4] _________ {T/F} Filling variables with the results of a Query is needed for both Web Applications and Stand Alone Database Applications.

Tables A, B, & C

1] _________________ X _________________ The dimensions of Table A are _?_ X _?_

2] _________________ X _________________ The dimensions of Table B are _?_ X _?_

3] _________________ X _________________ The dimensions of Table C are _?_ X _?_

4] Sketch the results of the natural join SELECT * FROM A, C

MySQL-2-HW.docx CSCI-3343 8 | P a g e

5] Sketch the results of the natural join SELECT * FROM C, A

Use Navicat

1] ______________ {Initial/Pledge} I have use the Navicat GUI to create a Database called Library2X

2] ______________ {Initial/Pledge} I have used the Navicat GUI to copy Users table (with the data) from Library2 to Library2X

3] ______________ {Initial/Pledge} I have used the Navicat GUI to delete fields UserTypeID, GradeLevelID, TeacherID, and Notes from table Users.

4] ______________ {Initial/Pledge} When I double-click on table Users, I get a listing that looks something like the following I have 8 fields/attributes:

5] ______________ {Initial/Pledge} I have used the Navicat GUI to delete all of the records/rows/tuples in which the ID >20.

6] Write the query that could be used to change all of the Passwords to "trinity"

7] ______________ {Initial/Pledge} I have use the Navicat Query to change all of the Passwords to "trinity".

8] Write the query that could be used to change all of the UserNames to ""

MySQL-2-HW.docx CSCI-3343 9 | P a g e

9] ______________ {Initial/Pledge} I have use the Navicat Query to change all of the UserNames to "".

10] ______________ {Initial/Pledge} When I double-click on table Users, I get a listing that looks something like the following:

11] Write the query that could be used to change all of the Passwords to "csci-" + ID Do so with Navicat!

12] Write the query that could be used to change all of the UserNames to lower case First + "." + Last Do so with Navicat!

13] ______________ {Initial/Pledge} When I double-click on table Users, I get a listing that looks something like the following:

DESIGN GOALS

IMPORTANT: We should never put more than one piece of information into each attribute/cell/field

IMPORTANT: We should design our database in such a way that we would not have to lock more than one record to implement changes.

IMPORTANT: We should design our database in such a way that we would not have multiple copies of the same information.

MySQL-2-HW.docx CSCI-3343 10 | P a g e

14] ______________ {Initial/Pledge} I have used the Navicat GUI to add the following fields/attributes: CourseNo, SectionNo, Prof to the Users table.

15] ______________ {Initial/Pledge} I have used the Navicat GUI to place the first 7 Users in : CSCI-3343, 1, Dr. Hicks.

16] ______________ Suppose the professor for section 1 of CSCI-3343 were to be changed to Dr. Hicks. How many records would have to be changed? If more than 1, BAD DESIGN!

17] Write the query that could be used to display the ID and FullName of all the folks in section 1 of CSCI-3343 Alphabetically by FullName Do so with Navicat!

MySQL-2-HW.docx CSCI-3343 11 | P a g e

18] ______________ {Initial/Pledge} But wait, it may be the case that a student would take up to 6 courses in a given semester. I have use Navicat to update the Users as follows:

19] ______________ {Initial/Pledge} The first course for Users.ID 8 is to be Section 1 of CSCI-4386 with Dr. Hicks and the second course is to be Section 2 CSCI-3343 With Dr. Lewis

20] ______________ {Initial/Pledge} The first course for Users.ID 9 is to be Section 2 of MATH-1301 with Dr. Rice and the second course is to be Section 3 of CHEM-1301 with Dr. Pursell and the third course is to be Section 2 CSCI-3343 With Dr. Lewis

21] ______________ {Initial/Pledge} The first course for Users.ID 10 is to be Section 3 of MATH-1320 with Dr. Elaydi and the second course is to be Section 3 of CHEM-1320 with Dr. Cooley and the third course is to be Section 1 CSCI-4386 With Dr. Hicks and the fourth course is to be Section 2 CSCI-3343 With Dr. Lewis

22] Write the query that could be used to display the ID and FullName of all the folks in CSCI-3343 Alphabetically by FullName Do so with Navicat!

MySQL-2-HW.docx CSCI-3343 12 | P a g e

22] Write the query that could be used to display the ID and FullName of all the folks in Section 1 of CSCI-3343 Alphabetically by FullName Do so with Navicat!

23] ______________ {Yes/No} Can you imagine how ugly this is going to get if we want to do up to eight course a semester for those students on the seven year plan 14 x 8 = 112 Course# fields, Not only BAD DESIGN, but really awful queries.

24] ______________ {Initial/Pledge} I have use the Navicat GUI to create a Database called Library2Y

25] ______________ {Initial/Pledge} I have used the Navicat GUI to copy Users table (with the data) from Library2X to Library2Y. I have altered the records to include only those fields shown above.

26] ______________ {Initial/Pledge} I have use the Navicat GUI to create Library2Y.Courses to match the Class Diagram for the User Sub-System (above)

MySQL-2-HW.docx CSCI-3343 13 | P a g e

27] ______________ {Initial/Pledge} Many Software Engineers would provide the development team a more detailed Class Diagram such as the User Sub-System class above make sure your layouts match those illustrated above.

28] ______________ {Initial/Pledge} I have added the 11 Courses (shown above) to my Database Library2Y

29] Write the query that could that will display the number of courses that are Spring courses Do so with Navicat! Hint: should get 2

30] Write the query that could that will display the number of courses that have been tagged for deletion Do so with Navicat! Hint: should get 1.

MySQL-2-HW.docx CSCI-3343 14 | P a g e

31] Write the query that could that will display the total number of courses (Deleted and Undeleted) Do so with Navicat! Hint: should get 11.

32] ______________ {Initial/Pledge} I will use the UserCourse Relationship/Table to add users to classes; I have created the UserCourse table shown above.

33] ______________ {Initial/Pledge} I have created table UserCourse.

In order to Place Users.ID = 1 Into Section 1 of CSCI-3343 during the Fall of 2018 we would add the following record to UserCourse:

34] ______________ {Initial/Pledge} I have done what is necessary to place the first 7 Users in : CSCI-3343, 1, Dr. Hicks.

35] ______________ {Initial/Pledge} I have done what is necessary to tag Dr. Hicks for Deletion.

MySQL-2-HW.docx CSCI-3343 15 | P a g e

36] Write the query that could be used to display the User's ID and FullName of all the folks in CourseID=1 Alphabetically by FullName Do so with Navicat! Don't Include Deleted Records Hint: Need Two Tables

37] Write the query that could be used to display Users.FullName, Users.ID, UserCourse.UserID, UserCourse.CourseID, Courses.ID, Courses.ID, CourseNo for all of the records in order by FullName Include the Deleted records as well Hint: Need Three Tables

38] ______________ {Initial/Pledge} I have done what is necessary to place Users.ID 8 in Fall 2018 Section 1 CSCI-4386 with Dr. Hicks and in Section 2 CSCI-3343 With Dr. Lewis

39] ______________ {Initial/Pledge} {Initial/Pledge} I have done what is necessary to place Users.ID 9 in Section 2 of MATH-1301 with Dr. Rice and in Section 3 of CHEM-1301 with Dr. Pursell and in Section 2 CSCI-3343 With Dr. Lewis

40] ______________ {Initial/Pledge} I have done what is necessary to place Users.ID 10 in Section 3 of MATH-1320 with Dr. Elaydi and in Section 3 of CHEM-1320 with Dr. Cooley and in Fall 2018 Section 1 CSCI-4386 With Dr. Hicks and in Section 2 CSCI-3343 With Dr. Lewis

MySQL-2-HW.docx CSCI-3343 16 | P a g e

41] Write the query that could that will display the total number of UserCourse records Do so with Navicat! Hint: should get 15 Should Use One Table

42] Write the query that could that will display the total number of users taking CSCI-3343 Do so with Navicat! Hint: should get 10 Should Use Two Tables

43] Write the query that could that will display the total number of users taking CSCI-3343 Do so with Navicat! Hint: should get 10 Should Use Two Tables

44] _________ {T/F} Dr. Hicks is showing a correct UserCourse file below.

MySQL-2-HW.docx CSCI-3343 17 | P a g e

45] _________ {T/F} We could use this design strategy to record all of the courses that each student takes.

Video & Internet #1Introduction To Databases (14 Min)

https://www.youtube.com/watch?v=D-k-h0GuFmE&list=PLroEs25KGvwzmvIxYHRhoGTz9w8LeXek0

1] Watch the video above.

2] _______________________________________________________________________________ According to the video, a D_?_ M_?_ System provides an efficient, reliable, convenient and safe multi-user storage and access to massive amounts of persistent data.

3] _______________________________________________________________________________ Databases handle data at a Ma_?_ scale often terabytes per day.

4] _______________________________________________________________________________ The data, handled by database systems, is typically Pe_?_ the data is there before the program starts, the program operates on the data, and the data is there after the program ends.

5] _______________________________________________________________________________ Database systems often run critical applications the data has to remain in a consistent state when there are failures (user, power, hardware, software, etc.) a number of built in Sa_?_ mechanisms are available.

6] _______________________________________________________________________________ Having M_?_ users using databases concurrently necessitates the need for concurrency controls .

7] _______________________________________________________________________________ Physical Data I_?_ means that the commands that operate on the data are independent upon the mechanisms that store the data if a data base designer were to implement a faster retrieval/storage algorithm.

8] _______________________________________________________________________________ Databases are generally queried by H_?_ Level Query Languages that describe what you want and not how you get it.

9] _______________________________________________________________________________ The most important three things in a database system are Performance, P_?_, and P_?_.

10] _______________________________________________________________________________ The standard for Rel_?_ is an UpTime of 99.99999% .

MySQL-2-HW.docx CSCI-3343 18 | P a g e

11] _______________________________________________________________________________ The Data M_?_ is a description of how the data is stored Relational Model, XML Data Model, Graph Data Model.

12] _______________________________________________________________________________ The Data De_?_ Language is used to set up a Schema.

13] _______________________________________________________________________________ DDL is an acronym for _?_.

14] _______________________________________________________________________________ Querying and manipulating the data would be done with a Data M_?_ Language.

15] _______________________________________________________________________________ DML is an acronym for _?_.

16] _______________________________________________________________________________The person who builds the actual Database System, such as MySQL, is often referred to a Database Im_?_.

17] _______________________________________________________________________________The person who establishes the Schema (structure) for the database is the Database De_?_ .

18] _______________________________________________________________________________The person who builds user application programs that interface with that database is the Database Ap_?_ might be stand alone or web based.

19] _______________________________________________________________________________The person who loads the Database and keeps it running smoothly is the Database Ad_?_ .

Video & Internet #2Relational Databases: The Relational Model (9 Min)

https://www.youtube.com/watch?v=spQ7IFksP9g

1] Watch the video above.

2] ______________________________________________________________________________________ Database = set of named Re _?_ (or Ta_?_).

3] ______________________________________________________________________________________ Each Relation, or Table, has a set of Named At_?_ (or Co_?_) (or Fi_?_)

4] ______________________________________________________________________________________ The Table Data is is a collection of Tu_?_ (or Ro_?_) or (Rec_?_) they have a value for each attribute.

5] ______________________________________________________________________________________ Each Attribute/Field has a Ty_?_ (or Do_?_).

6] ______________________________________________________________________________________ The Sc_?_ is a structural description of the database.

7] ______________________________________________________________________________________ An In_?_ is the actual data, in the database, at some point in time.

MySQL-2-HW.docx CSCI-3343 19 | P a g e

8] ______________________________________________________________________________________ N_?_ is a special value for "undefined" or "unknown"

9] ______________________________________________________________________________________ A Ke_?_ is an attribute/field whose value is unique in each tuple/record/row.

Video & Internet #3Querying Relational Databases (6 Min)

https://www.youtube.com/watch?v=nf1-h2GpEGc

1] Watch the video above.

2] What is meant by an "ad-hoc" query?

_________________________________________________________________________________________

_________________________________________________________________________________________

_________________________________________________________________________________________

3] ______________________________________________________________________________________ When you run a query across a set of relations/tables, you get a Re_?_ as a result.

4] ______________________________________________________________________________________ Compositionality is the ability to run a query over the results of a previous Qu_?_.

5] ______________________________________________________________________________________ The two query languages illustrated in the video were SQL and Re_?_.

Video & Internet #4 (Optional)Querying Relational Databases (6 Min)

https://www.youtube.com/watch?v=cVQUvZh64Y8

1] List one query, from the presentation, in Relational Algebra format.

What To Turn In

1] All pages of this lab with questions completed.

MySQL-2-HW.docx CSCI-3343 20 | P a g e

- - - - - - - - - - - No Lab Is Complete Until Both Are Complete - - - - - - - - - - -

1] You sign & submit the Pledge form at the top of this lab!. No Lab Will Be Considered Complete until this is done. Late penalties will continue to accrue until the pledge form is submitted.

a) Sign & Pledgeb) Record the amount of time you think you spent on this labc) Staple all pages of this lab. Fold in half length-wise (like a hot-dog). Put your name on the outside. Place it on the professor desk before the beginning of lecture on

the day it is due. The penalty for late homework will not exceed 25% off per day.d) Short answer questions must be hand written, unless the professor has granted an exception for physical reasons.

2] Place all programming code associated with this program, if any, in the Professor’s Code Drop Box or on the Virtual System as directed.I do not accept programs by mail; do not submit labs via email!