hw3

docx

School

Bluegrass Community and Technical College *

*We aren’t endorsed by this school

Course

244

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

2

Uploaded by MegaClover13750

Report
1. Write a sentence or two to describe the purpose of the following sqlite3 functions: a. Connect The purpose of the sqlite3 function connect is to establish a connection to a database. b. Execute The purpose of the sqlite3 function execute is to execute a command or query. c. Close The purpose of the sqlite3 function close is to close the connection to the database. 2. What is an SQL join? Is a join an efficient operation? Explain your answer. 3. Explain why the following data violates the relational database model by being in a normal form lower than third. The data violates the relationship database model because it shows transitive dependencies. In 3NF, non-prime attributes must be dependent on the primary key with no transitive dependencies between non-prime attributes. 4. Break up the table in (3) above into multiple tables so that the result is in 3NF. Table 1 order_num customer_ID 237 2242 248 4254 500 1234 501 1235 Table 2 customer_I D customer_name state tax_rate 2242 DeBerry DC 0.08 4254 Bailey MD 0.05 1234 Chirwa KY 0.06 1235 Nandanoor KY 0.06 Table 3 product price Wine 25.00 Chocolate 45.00 Gift Book 60.95 Jam 12.00 Peanuts 8.99 Xbox 150.00
Table 4 order_num product 237 Wine 237 Chocolate 248 Wine 248 Gift Book 248 Jam 500 Peanuts 501 Xbox 5. Consider an SQLite database that has a table called Stock with the following columns: a. Write a Python statement to execute an SQL SELECT statement that will query the table for all rows with PurchasePrice greater than 25.00 import sqlite3 with conn: rows = conn.execute("SELECT * FROM Stock WHERE PurchasePrice > 25.00").fetchall() for row in rows: print(row) b. Write a Python statement to execute an SQL INSERT statement that puts a new row in the table with TradingSymbol = XYZ, CompanyName = “XYZ Company”, NumberOfShares = 150, PurchasePrice = 12.55, SellingPrice = 22.47 import sqlite3 with conn: cursor.execute(“INSERT INTO Stock (TradingSymbol, CompanyName, NumberOfShares, PurchasePrice, SellingPrice) VALUES (?, ?, ?, ?, ?)”, (“XYZ”, “XYZ Company”, 150, 12.55, 22.47))
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