Skip to content
Question 21 of 29

Q.(A)

(i) Define cartesian product with respect to RDBMS.
(ii) Sunil wants to write a program in Python to update the quantity to 20 of the records whose item code is 111 in the table named shop in MySQL database named Keeper. The table shop in MySQL contains the following attributes: Item_code: Item code (Integer) Item_name: Name of item (String) Qty: Quantity of item (Integer) Price: Price of item (Integer) Consider the following to establish connectivity between Python and MySQL: Username: admin Password: Shopping Host: localhost
(OR)
(B)
(i) Give any two features of SQL.
(ii) Sumit wants to write a code in Python to display all the details of the passengers from the table flight in MySQL database, Travel. The table contains the following attributes: F_code: Flight code (String) F_name: Name of flight (String) Source: Departure city of flight (String) Destination: Destination city of flight (String) Consider the following to establish connectivity between Python and MySQL: Username: root Password: airplane Host: localhost
West Bengal WbchseCBSE Class XII Board 2024Subjective· 5mImportance★★★★★
72% · 21/29 Questions
🔒 Locked · start free trial →

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.