DAD 220 Database Documentation Template Murphy

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 BaronKuduPerson693

Report
DAD 220 Database Documentation Template 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 to Change the Ownership of MySQL: 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:
Commands/Explanation: CREATE DATABASE QuantigrationUpdates; - Creates new database with the name “QuantigrationUpdates”. SHOW DATABASES; - List all existing databases in the current database server. Verifies that the database “QuantigrationUpdates” was created. 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:
Commands/Explanation: USE QuantigrationUpdates; - Tells the system what database to use. CREATE TABLE Customers (CustomerID INT, FirstName VARCHAR(25), LastName VARCHAR(25), Street VARCHAR(50), City VARCHAR(50), State VARCHAR(25), ZipCode VARCHAR(10), Telephone VARCHAR(15), PRIMARY KEY(CustomerID)); - Creates a new table named “Customers” with several columns with it’s own data type and size. Designates the primary key as “CustomerID”. The primary key makes sure each entry into the “CustomerID” column is unique. DESCRIBE Customers; - Provides a description of the “Customers” table with the tables column names, data types, and any constraints associated with them.
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: Commands/Explanation: CREATE TABLE Orders (OrderID INT NOT NULL PRIMARY KEY, CustomerID INT, SKU VARCHAR(20), Description VARCHAR(50), FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)); - Creates a new table named “Orders” with a foreign key constraint 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. The relationship ensures that every value entered into the “CustomerID” column of the “Orders” table corresponds to the “CustomerID” column in the “Customers” table. Designated the primary key as “OrderID” to ensure each entry is unique. DESCRIBE Orders; - Provides a description of the “Orders” table with the table’s column names, data types, and any constraints associated with them. 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:
Commands/Explanation: 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)); - Creates a new table named “RMA” with a foreign key constraint 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. The relationship ensures that every value entered into the “OrderID” column of the “RMA” table corresponds to the “OrderID” column in the “Orders” table. Designated the primary key as “RMAID” to ensure each entry is unique. DESCRIBE RMA; - Provides a description of the “RMA” table with the table’s column names, data types, and any constraints associated with them. 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.
Commands/Explanation: LOAD DATA INFILE '/home/codio/workspace/customers.csv' INTO TABLE Customers FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'; - The “LOAD DATA INFILE” statement imports data from a CSV file named “customers.csv” located at '/home/codio/workspace/customers.csv' into the “Customers” table. The “INTO TABLE” clause specifies that the data will be inserted into the “Customers” table. The “FIELDS TERMINATED BY ','” clause indicates the fields in the CSV file are separated by commas. The “LINES TERMINATED BY '\r\n'” clause specifies the line-ending format in the CSV file. When executed, the database server reads the CSV files content, matches the comma-separated values to the appropriate columns in the “Customers” table, and inserts the data accordingly. LOAD DATA INFILE '/home/codio/workspace/orders.csv' INTO TABLE Orders FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'; - The “LOAD DATA INFILE” statement imports data from a CSV file named “orders.csv” located at '/home/codio/workspace/orders.csv' into the “Orders” table. The “INTO TABLE” clause specifies that the data will be inserted into the “Orders” table. The “FIELDS TERMINATED BY ','” clause indicates the fields in the CSV file are separated by commas. The “LINES
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
TERMINATED BY '\r\n'” clause specifies the line-ending format in the CSV file. When executed, the database server reads the CSV files content, matches the comma-separated values to the appropriate columns in the “Orders” table, and inserts the data accordingly. LOAD DATA INFILE '/home/codio/workspace/rma.csv' INTO TABLE RMA FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'; - The “LOAD DATA INFILE” statement imports data from a CSV file named “rma.csv” located at '/home/codio/workspace/rma.csv' into the “RMA” table. The “INTO TABLE” clause specifies that the data will be inserted into the “RMA” table. The “FIELDS TERMINATED BY ','” clause indicates the fields in the CSV file are separated by commas. The “LINES TERMINATED BY '\ r\n'” clause specifies the line-ending format in the CSV file. When executed, the database server reads the CSV files content, matches the comma-separated values to the appropriate columns in the “RMA” 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 have been returned. Commands/Explanation:
SELECT COUNT(*) FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID WHERE UPPER(Customers.city) = 'FRAMINGHAM' AND UPPER(Customers.state) = 'MASSACHUSETTS'; - This SQL query successfully counted the number of orders placed by customers who reside in 'FRAMINGHAM' 'MASSACHUSETTS'. It combines the “Customers” and “Orders” table using an “INNER JOIN” based on matching the “CustomerID” column, ensuring only customers with orders are included. The “WHERE” clause further filters the data by selecting customers from the specified city and state in a case-insensitive manner using the “UPPER()” function. The “COUNT(*)” function aggregates the data and returns the count of orders. 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 were returned. Commands/Explanation: SELECT COUNT(*) FROM Customers WHERE UPPER(Customers.state) = 'MASSACHUSETTS'; - This query selects and counts the number of rows where the state of the customer is 'MASSACHUSETTS' in the database table named “Customers” disregarding the case (as indicated by the UPPER function). The simple query efficiently retrieved the required information.
Write a SQL query to insert four new records into the Orders and Customers tables using the following data: Customers Table CustomerI D FirstName LastNam e StreetAddress City State ZipCod e 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 Commands/Explanation: 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 ' , ' Greensboro ' , ' NC ' , ' 27401 ' , ' 919-555-6623 ' ),
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
(100006, ' MaryAnne ', 'J enkins ' , ' 1 Coconut Way ' , ' Jupiter ' , ' FL ' , ' 33458 ' , ' 321-555-8907 ' ), (100007, ' Janet ' , ' Williams ' , ' 55 Redondo Beach Blvd ' , ' Torrance ' , ' CA ' , ' 90501 ' , ' 310-555-5678 ' ); - I used the INSERT INTO Customers command to tell the database that I wanted to insert information into the “Customers” table. The VALUES event tells the database that the information that follows is what I want inserted into the table. SELECT * FROM Customers WHERE CustomerID IN (100004, 100005, 100006, 100007); - This query verified that the information was inserted as requested. 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
Commands/Explanation: 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' ); - I used the INSERT INTO Orders command to tell the database that I wanted to insert information into the orders table. The VALUES event tells the database that the information that follows is what I want inserted into the table. SELECT * FROM Orders WHERE OrderID IN (1204305, 1204306, 1204307, 1204308); - This query verified that the information was inserted as requested. 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 Commands/Explanation: SELECT COUNT(*) FROM Customers WHERE UPPER(Customers.city) = 'Woonsocket' AND UPPER(Customers.state) = 'Rhode Island'; - I ran a command that told the database to count the number of customers in the “Customers” table where the city is “Woonsocket” and state is “Rhode Island”. This returned 7 records. 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? The current status is “Pending”, and the current step is “Awaiting customer Documentation”. Commands/Explanation: SELECT status, step FROM RMA WHERE OrderID = 5157; - I ran a command that told the database to show the status and step for the record in the “RMA” table where the order id is
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
5175. The current status is “Pending”, and the current step is “Awaiting customer Documentation”. 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 status is “Complete”, and the updated step is “Credit Customer Account”. Commands/Explanation: UPDATE RMA SET Status = 'Complete', Step = 'Credit Customer Account' WHERE OrderID = 5175; - I wrote a command that told the database to update the status and step for order id 5175 in the RMA table. SELECT status, step from RMA where OrderID = 5175; - I ran the command to show the status and step of order id 5175 in the RMA table to display that the updates were 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.
Command/Explanation: DELETE FROM RMA WHERE REASON = 'Rejected'; - I wrote a command that told the database to delete all records from the RMA table where the reason was rejected. This resulted in 596 records being deleted. 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.”
Commands/Explanation:
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
CREATE VIEW Collaborator AS SELECT CustomerID AS CollaboratorID, FirstName, LastName, Street, City, State , ZipCode, Telephone FROM Customers; - Renames “CustomerID” to “CollaboratorID” in the “Customers” table. ALTER TABLE Orders DROP FOREIGN KEY Orders_ibfk_1; - Drops the foreign key so that “Collaborator” table primary key can be renamed. ALTER TABLE Customers RENAME TO Collaborators; - Renames “Customers” table to “Collaborators”. ALTER TABLE Collaborators CHANGE CustomerID CollaboratorID INT; - Changes “CustomerID” to “CollaboratorID”. ALTER TABLE Orders ADD FOREIGN KEY(CollaboratorID) REFERENCES Collaborators(CollaboratorID); - Sets “CollaboratorID” as the foreign key. DESCRIBE Collaborators; - Verifies changes have been made successfully. DESCRIBE Orders; - Verifies changes have been made successfully. 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. Commands/Explanation: SELECT * FROM Orders INTO OUTFILE '/home/codio/workspace/orders-output.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'; - When the SQL command is executed, it exports the contents of the “Orders” table from the database to the specified CSV file, ‘orders-output’. Each row of
the “Orders” table will be written as a separate line in the csv file. The command executes successfully and affects 37998 rows.