AKINS DAD 220 DATABASE PROJECT

docx

School

Southern New Hampshire University *

*We aren’t endorsed by this school

Course

DAD 220

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

11

Uploaded by akinsaaliyah

Report
AALIYAH AKINS DAD 220 12/1/2023 DAD 220 Database Documentation Template Complete these steps as you work through the directions for Project One. Replace the bracketed text with your screenshots and brief explanations of the work they capture. Each screenshot and its explanation should be sized to approximately one quarter of the page, with the description written below the screenshot. Follow these rules for each of the prompts and questions below. Review the example document located in the Project One Supporting Materials for assistance. Step One: Create a Database 1. Navigate to your online integrated development environment (IDE). List and record the SQL commands that you used to complete this step here: Commands: chmod +x change_perm.sh ./change_perm.sh MySQL 2. Create a database schema called QuantigrationUpdates. List out the database name. Provide the SQL commands you ran against MySQL to successfully complete this in your answer: Command; CREATE DATABASE QuantigrationUpdates;
AALIYAH AKINS DAD 220 12/1/2023 show databases; 3. Using the entity relationship diagram (ERD) as a reference, create the following tables with the appropriate attributes and keys: a. A table named Customers in the QuantigrationUpdates database, as defined on the project ERD. Provide the SQL commands you ran against MySQL to complete this successfully in your answer: Command: CREATE TABLE Customers (CustomerID INT, FirstName VARCHAR(25), LastName VARCHAR(25), Street VARCHAR(50), City VARCHAR(50), State VARCHAR(25), ZipCode VACHAR(10), Telephone VARCHAR(15), PRIMARY KEY(CustomerID)); Explanation: The SQL command created a table named "Customers" in the database. The table contains several columns with their data type and size. The primary key CustomerID statement ensures that each entry in the CustomerID column is unique and is a reference point for identifying each customer record uniquely.
AALIYAH AKINS DAD 220 12/1/2023 b. A table named Orders in the QuantigrationUpdates database, as defined on the project ERD. Provide the SQL commands you ran against MySQL to complete this successfully in your answer Command: CREATE TABLE Orders (OrderID INT NOT NULL PRIMARY KEY, CustomerID INT, SKU VARCHAR(20), Description VARCHAR(50), FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)); Explanation: The SQL command created a table named "Orders" in the database. The table contains four rows. The FOREIGN KEY is used to create a relationship between the ‘Orders” table and the ‘Customers” table. It links the CustomerID column in the “Orders” table to the “CustomerID” column in the Customers table. This ensures that every value entered in the CustomerID column of the Order corresponds to an existing and valid CustomerID in the Customers table. c. A table named RMA in the QuantigrationUpdates database, as defined on the project ERD. Provide the SQL commands you ran against MySQL to complete this successfully in your answer: Command: CREATE TABLE RMA (RMAID INT NOT NULL PRIMARY KEY, OrderID INT, Step VARCHAR(50), Status VARCHAR(15), Reason VARCHAR(15), FOREIGN KEY (OrderID) References Orders(ORDERID)); Explanation: The "FOREIGN KEY" constraint is used to create a relationship between the "RMA" table and the "Orders" table. It links the "OrderID" column in the "RMA" table to the "OrderlD" column in the "Orders" table, establishing a foreign key relationship. This relationship ensures that every value entered in the "OrderlD" column of the "RMA" table must correspond to an existing and valid "OrderlD" in the "Orders" table.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
AALIYAH AKINS DAD 220 12/1/2023 Step Two: Load and Query the Data 1. Import the data from each file into tables. Use the QuantigrationUpdates database, the three tables you created, and the three CSV files preloaded into Codio. Use the import utility of your database program to load the data from each file into the table of the same name. You will perform this step three times, once for each table. For Customer Table LOAD DATA INFILE '/home/codio/workspace/customers.csv' INTO TABLE Customers FIELDS TERMINATED by',' LINES TERMINATED BY '\r\n'; For Orders Table LOAD DATA INFILE '/home/codio/workspace/orders.csv' INTO TABLE Orders FIELDS TERMINATED by',' LINES TERMINATED BY '\r\n'; For RMA Table LOAD DATA INFILE '/home/codio/workspace/rma.csv' INTO TABLE RMA FIELDS TERMINATED by',' LINES TERMINATED BY '\r\n'; 4. Write basic queries against imported tables to organize and analyze targeted data. For each query, replace the bracketed text with a screenshot of the query and its output. You should also include a 1- to 3-sentence description of the output. Write an SQL query that returns the count of orders for customers located only in the city of Framingham, Massachusetts. i. How many records were returned? 505
AALIYAH AKINS DAD 220 12/1/2023 Command: SELECT COUNT(*) FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID WHERE UPPER(Customers.city) = 'FRAMINGHAM' AND UPPER(Customers.state) = 'MASSACHUSETTS'; Explanation: This SQL query counted the number of orders placed by customers who reside in 'FRAMINGHAM', 'MASSACHUSETTS'. It combines the "Customers" and "Orders" tables using an "INNER JOIN" based on the matching “CustomerID" column, ensuring that only customers with orders are included. The "WHERE" clause further filters the data, selecting customers from the specified city and state "UPPER()" function. The "COUNT(*)" function totals the data and returns the count of orders. The output shows that there are 505 orders placed by customers in 'FRAMINGHAM', MASSACHUSETTS'. Write an SQL query to select all of the Customers located in the state of Massachusetts. i. Use a WHERE clause to limit the number of records in the Customers table to only those who are located in Massachusetts. ii. Record an answer to the following question: How many records were returned? 982 records returned Command: SELECT COUNT(*) FROM Customers WHERE UPPER(Customers.state) = 'MASSACHUSETTS'; Explanation: The query selects and counts the number of rows where the state of the customer is "MASSACHUSETTS," disregarding the case as indicated by the UPPER function. The result of the query shows that there are 982 customers in the database whose state is recorded as "MASSACHUSETTS." Write a SQL query to insert four new records into the Orders and Customers tables using the following data: Customers Table CustomerID FirstName LastName StreetAddress City State ZipCode Telephone 100004 Luke Skywalker 15 Maiden Lane New York NY 10222 212-555-1234 100005 Winston Smith 123 Sycamore Street Greensbor o NC 27401 919-555-6623 100006 MaryAnne Jenkins 1 Coconut Way Jupiter FL 33458 321-555-8907 100007 Janet Williams 55 Redondo Beach Blvd Torrence CA 90501 310-555-5678
AALIYAH AKINS DAD 220 12/1/2023 Commands: INSERT INTO Customers (CustomerID, FirstName, LastName, Street, City, State, ZipCode, Telephone) VALUES (100004, 'Luke', 'Skywalker', '15 Maiden Lane', 'New York', 'NY', 10222, '212-555- 1234'), (100005, 'Winston', 'Smith', '123 Sycamore Street', 'Greensborg', 'NC', 27401, '919- 555-6623'), (100006, 'MaryAnne', 'Jenkins', '1 Coconut Way', 'Jupiter', 'FL', 33458, '321-555- 8907'), (100007, 'Janet', 'Williams', '55 Redondo Beach Blvd', 'Torrence', 'CA', 90501, '310- 555-5678'); SELECT * FROM Customers WHERE CustomerID IN (100004, 100005, 100006, 100007); Explanation: The findings indicate that the insertion of four new records into the "Customers" table was successful. The INSERT statement added four rows with distinct "CustomerID" values (100004, 100005, 100006, and 100007) along with their corresponding first names, last names, streets, cities, states, zip codes, and telephone numbers. Since there are no duplicate warnings or errors reported, it confirms that all the inserts were completed without any issues or conflicts. Overall, the successful retrieval of the inserted data using the SELECT query demonstrates that the records were effectively added to the "Customers" table in the database, Orders Table
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
AALIYAH AKINS DAD 220 12/1/2023 OrderID CustomerID SKU Description 1204305 100004 ADV-24-10C Advanced Switch 10GigE Copper 24 port 1204306 100005 ADV-48-10F Advanced Switch 10 GigE Copper/Fiber 44 port copper 4 port fiber 1204307 100006 ENT-24-10F Enterprise Switch 10GigE SFP+ 24 Port 1204308 100007 ENT-48-10F Enterprise Switch 10GigE SFP+ 48 port Command: INSERT INTO Orders (OrderID, CustomerID, SKU, Description) VALUES (1204305, 100004, 'ADV-24-10C', 'Advanced Switch 10GigE Copper 24 port'), (1204306, 100005, 'ADV-48-10F', 'Advanced Switch 10 GigE Copper/Fiber 44 port copper 4 port fiber'), (1204307, 100006, 'ENT-24-10F', 'Enterprise Switch 10GigE SFP+ 24 Port'), (1204308, 100007, 'ENT-48-10F', 'Enterprise Switch 10GigE SFP+ 48 port'); SELECT * FROM Orders WHERE OrderID IN (1204305, 1204306, 1204307, 1204308); The findings indicate that the insertion of four new records into the "Orders" table was successful. The INSERT statement added four rows with specific values for "OrderlD," "CustomerID," "SKU," and "Description," as provided in the query. The SELECT query that followed confirms that the new orders were indeed inserted into the table. Each new order contains accurate information for the "OrderID," "CustomerID," "SKU," and "Description" fields. In the Customers table, perform a query to count all records where the city is Woonsocket, Rhode Island. i. How many records are in the Customers table where the field “city” equals “Woonsocket”? 7
AALIYAH AKINS DAD 220 12/1/2023 Command: SELECT COUNT(*) FROM Customers WHERE UPPER(Customers.city) = 'Woonsocket'; Explanation: The query successfully counted the number of records in the "Customers" table where the city name, is equal to 'WOONSOCKET'. The result of the query is 7. This means that there are 7 customers in the "Customers" table whose city is recorded as 'Woonsocket .' In the RMA database, update a customer’s records. i. Write an SQL statement to select the current fields of status and step for the record in the RMA table with an orderid value of “5175.” 1. What are the current status and step? Current status is pending and the step is awaiting customer documentation. Command: SELECT * FROM RMA WHERE OrderID = 5175; Explanation: ii. Write an SQL statement to update the status and step for the OrderID , 5175 to status = “Complete” and step = “Credit Customer Account.” 1. What are the updated status and step values for this record? Command UPDATE RMA SET Status = 'Complete', Step = 'Credit Customer Account' WHERE OrderID = 5175; SELECT * FROM RMA WHERE OrderID = 5175;
AALIYAH AKINS DAD 220 12/1/2023 Explanation: The SQL query updated the "RMA" table for the record where the "OrderlD" is 5175. It sets the "Status" to "Complete' and the "Step" to 'Credit Customer Account'. The result of the query shows that one row was affected, and the update was successful. The "Status" and "Step" values for the RMA record with OrderlD 5175 have been changed as follows: Step: "Credit Customer Account," Status: "Complete.” Delete RMA records. i. Write an SQL statement to delete all records with a reason of “Rejected.” 1. How many records were deleted? 596 records. Command: DELETE FROM RMA WHERE UPPER(Reason) LIKE'%REJ%'; Explanation: This SQL code deleted records from the "RMA" table. Specifically, it targets rows where the "Reason" column contains the substring 'REJ'. The % allows for matching any characters before or after the specified substring,"REJ', in the "Reason" column. It enables the code to find and delete rows where the reason contains the substring 'REJ' regardless of the characters before or after it. The query successfully deletes 596 rows. 5. Update your existing tables from “Customer” to “Collaborator” using SQL based on this change in requirements. Provide the SQL commands you ran against MySQL to complete this successfully in your answer: a. Rename all instances of “Customer” to “Collaborator.”
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
AALIYAH AKINS DAD 220 12/1/2023 Commands: Rename Table Customers TO Collaborators; ALTER TABLE Orders DROP FOREIGN KEY Orders_ibfk_1; ALTER TABLE Collaborators DROP PRIMARY KEY; ALTER TABLE Orders CHANGE CustomerID CollaboratorID INT; ALTER TABLE Collaborators ADD PRIMARY KEY(CollaboratorID); ALTER TABLE Collaborators CHANGE CustomerID CollaboratorID INT; Describe Orders; Describe Collaborators Explanation; First I renamed the table from customers to collaborators. I then dropped the foreign key using the first SQL code. This statement removed a foreign key constraint named Orders_ibfk 1 from the Orders table. The second SOL statement removed the primary key constraint from the Collaborators table. Dropping the primary key means that the table won't have a designated unique identifier, and records might not be uniquely identifiable based on a primary key.
AALIYAH AKINS DAD 220 12/1/2023 The third statement changed the name of the column CustomerlD in the Orders table to CollaboratorlD and also changed its data type to INT (integer). The fourth SQL statement changed the name and data type of the column CustomerID in the Collaborators table to CollaboratorID with the data type INT. The fifth command added a new primary key constraint to the Collaborators table, specifically on the column CollaboratorID. 6. Create an output file of the required query results. Write an SQL statement to list the contents of the Orders table and send the output to a file that has a .csv extension. Command: SELECT * FROM Orders INTO OUTFILE '/home/codio/workspace/qrma-orders-data85.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'; Explanation: Using this code exported the contents of the Orders table to a CSV file named qrma-orders- data85.csv. The MySQL query executes successfully and affects 37998 rows, which suggests that there are 37998 records in the Orders table order .