Running head: UNIT 4 RESEARCH PROJECT 1 Unit 4 Research Project Eddie S. Jackson Kaplan University IT526: SQL Query Design Jon Walter McKeeby, DSc, MBA 07/15/2014
Running head: UNIT 4 RESEARCH PROJECT 1
Unit 4 Research Project
Eddie S. Jackson
Kaplan University
IT526: SQL Query Design
Jon Walter McKeeby, DSc, MBA
07/15/2014
UNIT 4 RESEARCH PROJECT 2
Unit 4 Research Project
Part 1. Your database. (90 points)
a. Pick two tables that have a 1:M relationship from the database you designed in your
IT520 or IT525 course. If you have not taken IT520 or IT525, use the sample project in
the Unit4.DatabaseDesign document in Doc Sharing. Show the data dictionary and
sample data for those two tables. Using your data dictionary as a template, give the
CREATE TABLE statements for those two tables, including Primary Key and Foreign
Key constraints. (30)
The two tables I have selected are CUSTOMER and INVOICE, a one to many
relationship.
UNIT 4 RESEARCH PROJECT 3
The data dictionary for the customer table is
Field Description Data Type Allows Nulls Key
Customer_ID
The unique ID of the
customer INTEGER
Does not allow
nulls
Primary
Key
First_Name
The first name of the
customer
VARCHAR
(20)
Does not allow
nulls Not a Key
Last_Name
The last name of the
customer
VARCHAR
(30)
Does not allow
nulls Not a Key
Middle_Initial
The middle initial of the
customer VARCHAR (1) Allow nulls Not a Key
Phone
The phone number of the
customer
VARCHAR
(20) Allows nulls Not a Key
The email address of the
customer
VARCHAR
(40) Allows nulls Not a Key
Address
The street address of
customer
VARCHAR
(40)
Does not allow
nulls Not a Key
City
The city where the customer
lives in
VARCHAR
(40)
Does not allow
nulls Not a Key
State
State where the customer
lives CHAR (2)
Does not allow
nulls Not a Key
Zip
The state zip code of the
customer CHAR (5)
Does not allow
nulls Not a Key
The sample data for the customer table is
Custo
mer_
ID
First_
Name
Last_
Nam
e
Midd
le_Ini
tial
Phone Email Address City Stat
e
1 Lee Moss S 407-436-
1214
lm@hotma
il.com
12 Marvel
Ln
Orlando FL
2 Janis Jones A 925-231-
2184
JJ12@gmai
l.com
452 Center
Blvd
Phoenix AR
3 Jeff Moor
e
O 770-765-
2846
JMor@yah
oo.com
6754 Pine
Ave
Atlanta GA
4 Bob Nye E 207-733-
2224
MrBob@g
mail.com
111 Point Bangor ME
5 Larry Biggs N 512-461- LarryBigm 432 Austin TX
UNIT 4 RESEARCH PROJECT 4
6623 [email protected]
m
Ingenuity
6 Amy Pond D 214-991-
1628
DrWho@y
ahoo.com
781 Back Rd Dallas TX
7 Mike Smith NUL
L
334-131-
8934
MSmith@b
ellsouth.net
421
Washington
Ave
Black AL
8 Tyler Crew
s
E 919-118-
9922
KingMan
@hotmail.c
om
986
Wellinton Dr
Raleigh NC
9 Tom Stone M 803-914-
3333
DigiTech@
hotmail.co
m
381 Christian
Ave
Columbi
a
SC
10 Vic Johns A 615-997-
4421
NULL 2220 Marco
St
Nashvill
e
TN
The data dictionary for the invoice table is
Field Description Data Type Allows Nulls Key
Invoice_ID The unique ID of the invoice INTEGER
Does not allow
nulls
Primary
Key
Date The date the invoice is issued DATE
Does not allow
nulls Not a Key
Subtotal
The subtotal of purchased
items
VARCHAR
(30)
Does not allow
nulls Not a Key
Tax The tax levied VARCHAR (2) Allow nulls Not a Key
Total
The total amount of purchase
with tax
VARCHAR
(20)
Does not allow
nulls Not a Key
Customer_ID Unique ID of customer INTEGER
Does not allow
nulls
Foreign
Key
The sample data for the invoice table is
Invoice_ID Date Subtotal Tax Total Customer_ID
1 06/02/2014 12.12 .06 12.85 1
2 06/03/2014 8.75 .04 9.10 1
3 06/04/2014 33.63 .07 35.98 5
4 06/05/2014 94.00 .09 102.46 7
5 06/06/2014 23.99 .04 24.95 3
UNIT 4 RESEARCH PROJECT 5
6 06/07/2014 85.12 .05 89.38 3
7 06/07/2014 22.52 .05 23.646 7
8 06/08/2014 73.15 NULL 73.15 7
9 06/09/2014 15.77 .06 16.72 7
10 06/10/2014 51.99 .08 56.15 4
I create a database
CREATE DATABASE robot;
I select the database
USE robot;
The CREATE TABLE statements are
(Ben-Gan, Sarka, & Talmage, 2013).
UNIT 4 RESEARCH PROJECT 6
b. Give INSERT statements that would insert at least five rows of data into each table. (10)
The INSERT for the Customer table
The INSERT for the Invoice table
(W3Schools, n.d.).
UNIT 4 RESEARCH PROJECT 7
c. Show the results of SELECT * FROM <tablename> for each of your tables. Paste each result
set into your Assignment Word document. Then paste into Word a screen image of the two result
sets. The Object Explorer pane should show the Databases folder expanded to show your
database, and its Tables folder expanded to show your two tables. [Eliminate white space in
SSMS so the characters in the screen image are readable without magnification. Use
ALT+PrintScreen to get an image of only SSMS and not the entire desktop.] (10)
The Customer table
The Invoice Table
d. Create a view for your database. Explain the purpose of the view, i.e., state why you feel the
view is necessary. Give the CREATE VIEW code for your view. (15)
This view created to reduce the complexity of the frequently used invoice table. Normally, the
invoice table has possible values for Invoice_ID, Date, Subtotal, Tax, Total, and Customer_ID.
For the use of the invoice itself, all that is really needed is the Invoice_ID, Date, and Total, thus
the below has been created.
UNIT 4 RESEARCH PROJECT 8
e. Update data in your database. Explain the purpose of the update. (10)
An update was required to the robot database due to Florida increasing its sales tax from 6
percent to seven percent. To make this change, the following UPDATE was created:
f. Show the results of SELECT * FROM <tablename> for the table(s) that have updated data.
(2.5)
These are the results from the above update (the updated tax rows are outlined):
UNIT 4 RESEARCH PROJECT 9
g. Delete one or more rows of data from a table in your database. Explain the purpose of the
delete. (10)
Due to a recent complaint from customer Lee Moss, the Robot Emporium is refunding the
customer’s purchases, and deleting the records from the database. The following shows the
delete. The invoice ID’s that must be deleted are invoice numbers 1 and 2.
h. Show the results of SELECT * FROM <tablename> for the table that had a row deleted. (2.5)
UNIT 4 RESEARCH PROJECT 10
Part 2. Inline Table-Valued Function (10 points)
The following view returns the total number of orders for each customer:
Create an inline table-valued function named Sales.fn_NumOrdersByCustomer that returns the
custid and the total number of orders for a specified custid.The Function
(Microsoft, 2014).
UNIT 4 RESEARCH PROJECT 11
The returned output for the specific CustID 2 is
UNIT 4 RESEARCH PROJECT 12
References
Ben-Gan, I., Sarka, D., & Talmage, R. (2013). Training Kit (Exam 70-461): Querying
Microsoft® SQL Server® 2012. Sabastopol, CA: O'Reilly Media, Inc.
Microsoft. (2014). CREATE FUNCTION (Transact-SQL). Retrieved from
http://msdn.microsoft.com/en-us/library/ms186755.aspx
W3Schools. (n.d.). SQL INSERT INTO Statement. Retrieved from http://www.w3schools.com
/sql/sql_insert.asp