Knox DAD220 Module6 Project 1

docx

School

Southern New Hampshire University *

*We aren’t endorsed by this school

Course

220

Subject

Mechanical Engineering

Date

Feb 20, 2024

Type

docx

Pages

18

Uploaded by AmbassadorFlowerCapybara40

Report
DAD 220 Database Documentation 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: Explanation: Changed permissions in MySQL using the code provided below. 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:
Explanation: Created database QuantigrationUpdates and listed available databases. The show databases command lists all available databases. Commands: CREATE DATABASE QuantigrationUpdates; 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:
Explanation: Created a table named Customers according to the ERD. The show tables command verifies the table was created and the describe command verifies the information within the table. Commands: CREATE TABLE Customers (CustomerID INT, FirstName VARCHAR(25), LastName VARCHAR(25), StreetAddress VARCHAR(50), City VARCHAR(50), State VARCHAR(25), ZipCode VARCHAR(15), Telephone VARCHAR(15), PRIMARY KEY(CustomerID)); Show tables; Describe Customers;
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
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: Explanation: Created table Orders in accordance with ERD. Show tables lists available tables in the database QuantigrationUpdates. The describe verifies the information entered. Commands: CREATE TABLE Orders (OrderID INT NOT NULL PRIMARY KEY, CustomerID INT, SKU VARCHAR(20), Description VARCHAR(50), FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)); show tables; describe ORDERS;
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: Explanation: Created the table RMA in accordance with the provided ERD. The show tables command verifies that the table was created. The command describe RMA verifies the information for the table was input correctly. Commands: 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)); Show tables; Describe RMA; 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. Explanation: Loaded data for the tables Customers, Orders, and RMA from .csv file via import utility with respective LOAD DATA INFILE commands. Commands:
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
Customers LOAD DATA INFILE '/home/codio/workspace/customers.csv' INTO TABLE Customers FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'; Orders LOAD DATA INFILE '/home/codio/workspace/orders.csv' INTO TABLE Orders FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'; RMA LOAD DATA INFILE '/home/codio/workspace/rma.csv' INTO TABLE RMA FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'; 2. 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 records returned as a result of the query.
Explanation: This query returned with a count of 505 customers with orders in the city of Framingham, Massachusetts. This query combined the tables Customers and Orders with an INNER JOIN. The Customer ID clause ensures that only customers with an order are populated while the WHERE clause whittles the results down further to only those in Framingham. 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 as a result of the query. Explanation: This query resulted in the return of 982 records of customers in the state of Massachusetts. My command was simple and broad, selecting all customers from MA only. These customers all have MA listed as their state of record. 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 Explanation: The INSERT command allowed 4 new records to be created in the Customers table with the corresponding data from above. The SELECT * command verifies that the customers have been added with the correct data. Commands:
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
INSERT INTO Customers (CustomerID, FirstName, LastName, StreetAddress, City, State, ZipCode, Telephone) Values (100004,'Luke','Skywalker','15 Maiden Lane','New York','NY','1022','212-555-1234'), (100005,'Winston','Smith','123 Sycamore Street','Greensboro','NC','27401','919-555-6623'), (100006,'MaryAnne','Jenkins','1 Coconut Way','Jupiter','FL','33458','321-555-8907'), (100007,'Janet','Williams','55 Redondo Beach Blvd','Torrance','CA','90501','310-555-5678'); SELECT * FROM Customers WHERE CustomerID IN (100004, 100005, 100006, 100007); Orders Table 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
Explanation: The INSERT INTO command allowed the addition of 4 new records to the table Orders. 4 columns worth of data (located above) were utilized in this command. The SELECT * command from orders table with the specific orderID’s verifies the data was input correctly. Commands: 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 10GigE Copper/Fiber 44 port copper 4 port fiber'), (1204307, 100006, 'ENT-24-10F',' Advanced 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);
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 records returned where the filed city equals Woonsocket. Explanation: The SELECT command allowed retrieval of the 7 records where the city is Woonsocket. This command has a WHERE clause which restricts records of all customers, to only records of customers with Woonsocket as the city of record. Commands: SELECT COUNT(*) FROM Customers WHERE UPPER(Customers.City) = '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?
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
Status and step of the order at current time is Pending, and Awaiting customer Documentation, respectively. Explanation: My query resulted in 1 record. The status is Pending, and the step is Awaiting customer Documentation. The customer is required to send documents and they must be processed before the step and status can change. Commands: SELECT * FROM RMA WHERE OrderID = 5175; 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? The updated values for status and step are Complete and Credit Customer Account.
Explanation: Status and step where updated to Complete and Credit customer Account. The clause limits the UPDATE action to only order 5175. This order can now be considered satisfactory. Commands: UPDATE RMA SET Status = 'Complete', Step = 'Credit Customer Account' WHERE OrderID = 5175; SELECT * FROM RMA WHERE OrderID = 5175; Delete RMA records. i. Write an SQL statement to delete all records with a reason of “Rejected.” 1. How many records were deleted? 596 rows were deleted as a result of this query. Explanation: 596 rows were deleted using the commands provided below. The % character is a wildcard and finds all likenessesof “REJ” and the DELETE command removes them from the database. The second command, SELECT from the wildcard REJ now results in an empty set proving that the records have been deleted. Commands: DELETE FROM RMA WHERE UPPER(Reason) LIKE '%REJ%'; SELECT * FROM RMA WHERE UPPER(Reason) LIKE '%REJ%';
3. 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
Explanation: Changed the name of the table from Customers to Collaborator. Then systematically removed traces of the word Customers, replacing it with Collaborator. This included dropping and reestablishing primary and foreign keys which once used the word Customers and now use the word Collaborator. Describe Customers; Describe Orders show that the table has been renamed and that all keys have been renamed as well. Commands: ALTER TABLE Customers RENAME Collaborator; show tables;
ALTER TABLE Collaborators DROP PRIMARY KEY; ALTER TABLE Collaborator CHANGE CustomerID CollaboratorID INT; ALTER TABLE Collaborator ADD PRIMARY KEY(CollaboratorID); ALTER TABLE Orders CHANGE CustomerID CollaboratorID INT; ALTER TABLE Orders ADD FOREIGN KEY(CollaboratorID) REFERENCES Collaborator(CollaboratorID); ALTER TABLE Orders DROP FOREIGN KEY Orders_ibfk_1; DESCRIBE Orders; DESCRIBE Collaborator; 4. 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.
Explanation: Exported the contents of the orders table via a csv file. This affected 37998 rows of records. The csv file will make it easier for analysists to upload the info into Excel. Commands: SELECT * FROM Orders INTO OUTFILE '/home/codio/workspace/qrma-orders-data85.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n';
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