Q.(A)
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Part (a): Cartesian product pairs every row of one table with every row of another (m x n rows); Python code UPDATEs shop.Qty to 20 where Item_code=111 and commits. Part (b): two SQL features (declarative; DDL+DML support) and Python code that SELECTs and prints all flight rows.
Part (a)
(i) Cartesian product (cross product) with respect to an RDBMS combines two relations so that each row of the first table is joined with every row of the second table. If the first has m tuples and the second has n tuples, the Cartesian product has m x n tuples, and the number of columns is the sum of the two tables' columns. In SQL it results from a CROSS JOIN, or from SELECT * FROM A, B with no WHERE join condition. It is the basis on which joins are built, though used unfiltered it produces an explosion of rows.
(ii) The Python-MySQL workflow is: import the connector, connect, get a cursor, execute the SQL, commit (mandatory for INSERT/UPDATE/DELETE), then close.
import mysql.connector
con = mysql.connector.connect(host="localhost", user="admin",
password="Shopping", database="Keeper")
cur = con.cursor()
cur.execute("UPDATE shop SET Qty = 20 WHERE Item_code = 111")
con.commit() # without commit the change is not saved
print(cur.rowcount, "record(s) updated")
con.close() …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.