Project_one_DAD 220 Database Documentation Template

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

17

Uploaded by PrivateIce3976

Report
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: 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:
CODE USED: CREATE DATABASE QuantigrationUpdates; EXPLANATION : This command created a new database with the name “QuantigrationUpdates.” The “CREATE DATABASE” statement is used to initiate the creation of a new database in a database management system. After executing this command, the system attempted to xr4eate a new and empty database with the specified name, “QuantigrationUpdates.” CODE USED: SHOW Databases; EXPLANATION: This command is typically used in systems like MySQL to display a list of existing databases in the current database server. When I executed the “SHOW Databases” command the
system returned a result set containing the names of all the databases present on the server which includes “QuantigrationUpdates” as well. This means the database was created successfully. 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: CODE USED: CREATE TABLE Customers (CustomerID INT, FirstName VARCHAR(25), LastName VARCHAR(25), StreetAddress VARCHAR(50), City VARCHAR(50), State VARCHAR(25), ZipCode VARCHAR(10), Telephone VARCHAR(15), PRIMARY KEY(CustomerID)); EXPLANATION: This command created a new table named “Customers” in the database. The table contains several columns, each with its own data type and size. The PRIMARY KEY (CustomerID) statement at the end designates the “CustomerID” columns as the primary key for the table. The primary key ensures each entry in the “CustomerID’ column is unique and serves as a reference point for identifying each customer record uniquely CODE USED: DESCRIBE Customers; EXPLANATION: This command provides a description of the “Customers” table’s structure, displaying information about its columns and their data types. When I executed this command, the database management system returned the table’s columns, such as their names, data types, and any constraints associated with them. It validated the successful execution of the previous SQL command. 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:
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
CODE USED: CREATE TABLE Orders (OrderID INT NOT NULL PRIMARY KEY, CustomerID INT, SKU VARCHAR(20), Description VARCHAR(50), FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)); DESCRIBE Orders; EXPLANATION: The first command created a table names “Orders” in the database. The table has four rows. The FOREIGN KEY constraint 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, establishing a foreign key relationship. This relationship ensures that every value entered in the “CustomerID” column of the “Orders” table must correspond to an existing and valid “CustomerID” in the “Customers” table. The helps the database maintain referential integrity and ensures that orders are associated with valid customer IDs. The second command provides a description of the “Orders” table’s structure, displaying information about its columns and their data types, as well as any constraints present. When I executed this command, the database management system returned details about the table’s schema, such as column names, data types, and constraints like primary key and foreign key relationships. It validated the successful creation of the Orders 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: CODE USED :
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)); DESCRIBE RMA; EXPLANATION: The first command created a table named “RMA” in the database. The table has the following columns: RMAID (this column stores unique identifiers for each Return Merchandise Authorization (RMA). The “NOT NULL” constraint ensures that every entry in this column must have a valid and non-null value. The “PRIMARY KEY” constraint designates the “RMAID” column as the primary key for the table, ensuring that each RMA has a unique identifier, OrderID (this column will store identifiers linking each RMA to the order it pertains to), Step, Status, and Reason columns. 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 “OrderID” column in the “Orders” table, establishing a foreign key relationship. This relationship ensures that every value entered in the “OrderID” column of the “RMA” table must correspond to an existing and valid “OrderID” in the “Orders” table. This way, the database maintains referential integrity that RMAs are associated with valid order IDs. The second command provides a description of the “RMA” table’s structure, displaying information about its columns and their data types, as well as any constraints present. When I executed this command, the database management system returned details about the table’s schema, such as column names, data types, and constraints like the primary key and foreign key relationships. It validated the successful creation of the RMA table. 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. CODE USED:
For the Customers Table: LOAD DATA INFILE ‘/home/codio/workspace/customers.csv’ INTO TABLE Customers FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\r\n’; EXPLANATION : This SQL code represents a data loading operation for the “Customers” table. The “LOAD DATA INFILE” statement is used to import data from a CSV file named “customer.csv” located at ‘/home/codio/workspace/customers.csv’ into the “Customers” table. The “INTO TABLE Customers” clause specifies that the fields in the CSVV file are separated by commas, while the “LINES TERMINATED BY ‘\r\n’ clause specifies the line-ending format in the CSV file. When executed, the database server reads the CSV file’s content, matches the comma separated clause to the appropriate columns in the “Customers” table and inserts the data accordingly. For the Orders Table: LOAD DATA INFILE ‘/home/codio/workspace/orders.csv’ INTO TABLE Orders FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\r\n’; EXPLANATION : This SQL code represents a data operation for the “Orders” table. The “LOAD DATA INFILE” statement is used to import data from a CSV file named “orders.csv” located at ‘/home/codio/workspace/orders.csv’ into the Orders table. The FIELDS TERMINATED BY ‘,’ clause specifies that the fields in the CSV file are separated by commas, while the LINES TERMINATED BY ‘\r\n’ clause specifies the line-ending format in the CSV file. When executed, the database server reads the CSV file’s content, matches the comma separated clause to the appropriate columns in the “Orders” table and inserts the data accordingly. For the RMA Table: LOAD DATA INFILE ‘/home/codio/workspace/rma.csv’ INTO TABLE RMA FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\r\n’; EXPLANATION: This SQL code represents a data operation for the “RMA” table. The “LOAD DATA INFILE” statement is used to import data from a CSV file named “rma.csv” located at ‘/home/codio/workspace/rma.csv’ into the RMA table. The INTO TABLE RMA clause specifies that the data in the CSV file are inserted into the RMA table. The FIELDS TERMINATED BY ‘,’ clause indicates that the fields in the CSV file are separated by commas, while the LINES TERMINATED BY ‘\r\n’ clause specifies the line-ending format in the CSV file. When executed, the database server reads the CSV file’s content, matches the comma separated clause to the appropriate columns in the “Orders” table and inserts the data accordingly. 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 were returned.
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
CODE USED: 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 successfully counted the number of orders placed by customers who resides 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 in a case-sensitive manner using the UPPER function. The COUNT(*) function aggregates 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 where returned.
CODE USED: SELECT COUNT(*) FROM Customers WHERE UPPER(Customers.state) = ‘MASSACHUSETTS’; EXPLANATION: I performed this query on a databased table named “Customers”. 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. This simple SQL query efficiently retrieved required information and yielded 982 as the count of customers from the state of Massachusetts. Write a SQL query to insert four new records into the Orders and Customers tables using the following data:
CODE USED: INSERT INTO Customers (CustomerID, FirstName, LastName, StreetAddress, City, State, ZipCode, Telephone) VALUES (100004, ‘Luke’, ‘Skywalker’, ’15 Maiden Lane’, ‘New York’, ‘NY’, 10222, ‘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); 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 (10004,100005,100006,100007) along with their corresponding first names, last names, street addresses, cities, states, zip codes and telephone numbers. The query’s results show that the newly inserted data matches the values provided in the INSERT statement. Each new record contains accurate information for the first name, last name, street address, city, state, zip code and telephone number. Since there are no duplicate warnings or errors reported, it confirmed that all the inserts were completed without any issues or conflicts. Overall, the successful retrieval if the inserted data using the SELECT query demonstrates that the records were effectively added to the “Customers” tables in the database. Customers 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
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 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
CODE USED: 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); EXPLANATION : 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 OrderID, CustomerID, SKU and Description, as provided in the query. The SELECT query that followed confirmed 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 records were returned.
CODE USED: SELECT COUNT(*) FROM Customers WHERE UPPER(Customers.City) = ‘WOONSOCKET’; EXPLANATION : The SQL query I executed is designed to count the number of records in the “Customers” table where the city name, when converted to uppercase, is equal to ‘WOONSOCKET’. The result of the query was 7. Thos means that there are 7 customers in the Customers table whose city is recorded as Woonsocket. The use of the UPPER function in the WHERE clause ensures that the comparison is case-sensitive. So, regardless of whether the city name is stored as ‘Woonsocket’, ‘WOONSOCKET’ or ‘woonsocket’, all such records will be counted as long as the city name matches ‘WOONCOCKET’ in uppercase. 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
CODE USED: SELECT * FROM RMA WHERE OrderID = 5175; EXPLANATION: The status of this RMA is “Pending,” indicating that the return process is still going. The step “Awaiting customer Documentation,” which implies that the customer is expected to provide some documentation or information to proceed with the return process. The reason for the return is “Defective,” indicating that the customer is returning the merchandise due to a defect or issue with the product. 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?
CODE USED: UPDATE RMA SET Status = ‘Complete’, Step = ‘Credit Customer Account’ WHERE OrderID = 5175; SELECT * FROM RMA WHERE OrderID = 5175; EXPLANATION : The SQL query I executed updated the RMA table for the record where the OrderID 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. 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 were deleted.
CODE USED: DELETE FROM RMA WHERE UPPER(Reason) LIKE ‘%REJ%’; EXPLANATION: The SQL code deleted record from the RMA table. Specifically, it targets rows where the Reason column, when converted to uppercase, contains the substring ‘REJ.’ The % symbol in the code is a wild card character in SQL’s LIKE statement to represent any sequence of characters (including none). In this specific context, % allows for matching any characters before or after the specified substring 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 records meeting these conditions. 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
CODE USED: ALTER TABLE Orders DROP FOREIGN KEY Orders_ibfk_1; RENAME TABLE Customers TO Collaborators; ALTER TABLE Collaborators DROP PRIMARY KEY; ALTER TABLE Orders CHANGE CustomerID CollaboratorID INT; ALTER TABLE Collaborators CHANGE CustomerID CollaboratorID INT; ALTER TABLE Collaborators ADD PRIMARY KEY(CollaboratorID); ALTER TABLE Orders ADD FOREIGN KEY(CollaboratorID) REFERENCES Collaborators(CollaboratorID); DESCRIBE Orders; DESCRIBE Collaborators; DESCRIBE Customers; EXPLANATION : First, I dropped the foreign key using the first SQL command. This statement removed a foreign key constraint named Order_ibfk_1 from the Orders table. The SQL 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. The third statement changed the name of the column CustomerID in the Orders table to CollaboratorID, and also changed its data type to INT. 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 Collaborator table, specifically on the column CollaboratorID. The sixth command added a new foreign key constraint to the Orders table. It creates a
relationship between the CollaboratorID column in the Orders table and the CollaboratorID column in the Collaborator table. 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. CODE USED: SELECT * FROM Orders INTO OUTFILE ‘/home/codio/workspace/qrma-orders-data85.csv’ FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\r\n’; EXPLANATION: This SQL code is an example of exporting the contents of the Orders table to a CSV file named qrma-orders-data85.csv. The data will be formatted with fields separated by commas and lines terminated by carriage return and newline characters. The MySQL query executes successfully and affects 37998 rows which suggests that there are 37998 records in the Orders table. The resulting CSV file likely contains a snapshot of the Orders table’s data, where each row represents an order and columns represent various attributes associated with each other.