Вы находитесь на странице: 1из 9

Alexander Nazario

SD 2520
Lab 5.1

LAB 5.1 (4.0 HOURS)


Assessment Preparation Checklist:
To prepare for this assessment:

Go through Chapter 7, pp. 123149 in the textbook, Introduction to


Database and XML with jQuery. This chapter explores how to run
queries using a database management system for a given set of
business rules.

Go through this modules lesson, which describes how queries are run
in MySQL.

Title: Working with SQL Queries


In this lab, you will design and run SQL queries for the given set of business
rules.
Required Setup and Resources:

Windows XP (or later)

MySQL

Recommended Procedure:
Note: For the steps that require you to paste screen shots or answer a
question, document your response in a Microsoft Word worksheet titled
SD2520_Module 5_Lab5_1.docx. Make sure to assign a corresponding task
number against each response or screen shot.
Task 1: Executing SELECT Queries
1

Launch ITT-Lab.

Launch MySQL Workbench.

Double-click Local Instance MySQL55.

If prompted, type the root password and click OK.

Select mydb.

Type the following query and then click Execute.

Alexander Nazario
SD 2520
Lab 5.1

Question 1: How many rows were returned?


Zero
___________________________________________________________
Question 2: How many columns were returned?
Two
__________________________________________________________
7

Type and execute a query that returns all rows and columns of the
Patients table.

Question 3: What query did you execute?


select * From patients

_____________________________________________________________
8

Execute a query that returns only the FirstName, LastName, and


PhoneNumber columns of the Patients table.

Question 4: What query did you execute?


select FirstName, LastName, PhoneNumber from patients

_____________________________________________________________
9

Execute a query that returns the LastName of only the patients that
have a DoctorKey column of 123.

Question 5: What query did you execute?


Select LastName

Alexander Nazario
SD 2520
Lab 5.1

_____________________________________________________________
10 Execute the following query:
SELECT Count(*) FROM Patients WHERE DoctorKey = 123

Question 6: What did this query tell you?


Nothing Error Code: 1064
_____________________________________________________________
11 Execute the following query:
SELECT * FROM Patients
WHERE MiddleName IS NULL OR FirstName = 'George'

You can use IS NULL and IS NOT NULL to check whether a column that
allows null contains a value or null.
Task 2: Executing DML Statements
1. Execute the following query:
INSERT INTO Patients
(PatientKey, DoctorKey, FirstName, MiddleName, LastName,
PhoneNumber)VALUES ('2-3','22222','Susan',NULL,'Michaels','5554444')

Alexander Nazario
SD 2520
Lab 5.1

2. Execute a SELECT statement to verify that the record exists. Take a


screen shot and paste it on your worksheet.

3. Execute a query that assigns Susan Michaels to the Experimental


group.

Question 7: What query did you execute?

insert into droppedpatients(DateDropped,PatientKey,ReasonDropped)


values('030314',3,'patient moved')

_____________________________________________________________
4. Execute the following statement:
UPDATE Patients
SET DoctorKey = 123
WHERE PatientKey = 2

5. Execute a query that assigns all patients currently assigned to Dr.


Jones to Dr. Thomas.

Alexander Nazario
SD 2520
Lab 5.1

Question 8: Which query did you execute?


_____________________________________________________________

Question 9: How many rows were affected?


_____________________________________________________________
Task 3: Executing Queries that Perform Joins
1 Execute the following query:
SELECT FirstName, LastName, DoctorName AS Doctor
FROM Patients
JOIN Doctors ON Patients.doctors_DoctorKey = Doctors.DoctorKey

2 Take a screen shot of the results and paste it on your worksheet.

3 Execute the following query:


SELECT FirstName, LastName, DoctorName AS Doctor
FROM Patients
RIGHT JOIN Doctors ON Patients.doctors_DoctorKey =
Doctors.DoctorKey

Alexander Nazario
SD 2520
Lab 5.1

4 Take a screen shot and paste it on your worksheet.

Question 10: How did the results differ from the query you ran in step
1? Explain why.
_____________________________________________________________
5

Execute the following query:


SELECT FirstName, LastName, DoctorName AS Doctor
FROM Patients
RIGHT JOIN Doctors ON Patients.doctors_DoctorKey =
Doctors.DoctorKey
JOIN patients_has_groups ON Patients_PatientKey =
Patients.PatientKey
WHERE Groups_GroupKey=1

Alexander Nazario
SD 2520
Lab 5.1

6 Take a screen shot and paste it in your worksheet.

7 Execute the following statement:


SELECT Doctors.DoctorName, COUNT(*)
FROM Patients
RIGHT JOIN Doctors ON Patients.doctors_DoctorKey =
Doctors.DoctorKey
JOIN patients_has_groups ON Patients_PatientKey =
Patients.PatientKey
GROUP BY Doctors.DoctorName

Alexander Nazario
SD 2520
Lab 5.1

8 Take a screen shot and paste it on your worksheet.

Submission Requirements:

For this lab, you need to submit the Microsoft Word document titled
SD2520_Module 5_Lab5-1.docx to your instructor.

Evaluation Criteria:
The lab rubric will be used to evaluate this assessment. In addition, your
submission will be evaluated against the following points:

Did you successfully execute the SELECT statements?

Did you successfully execute the DML statements?

Did you successfully execute joins?

Did you include all the screen shots in the Word document?

Did you answer all questions in the Word document?

Alexander Nazario
SD 2520
Lab 5.1

Вам также может понравиться