CBSE · 083Class XII · 2024Section E5 marks

Question 35

2 April 2024 · Computer Science (083)

(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

Answer

(i) Cartesian Product is an operation that combines rows/tuples from two tables/relations. It results in all possible pairs of rows from both tables and is denoted by 'X'. If table A has m rows and table B has n rows, the Cartesian product has m × n rows.

(ii)

python
import pymysql as pm

DB = pm.connect(host="localhost", user="admin",
                passwd="Shopping", database="Keeper")
MyCursor = DB.cursor()
MyCursor.execute("UPDATE shop SET Qty=20 WHERE Item_code=111")
DB.commit()
DB.close()

Explanation

(i) Defines the cross-product relational operation. (ii) Connects to MySQL via pymysql, executes the UPDATE, commits, and closes.