Many-to-Many Relationships and Python :Using Databases with Python (Python for Everybody Specialization) Answers 2025
Question 1
How do we model a many-to-many relationship between two database tables?
✅ We add a table with two foreign keys
❌ ARRAY column type
❌ 10 foreign keys
❌ BLOB columns
Explanation:
A junction (association) table is used to model many-to-many relationships.
For example, a StudentCourse table connects Students and Courses using two foreign keys: student_id and course_id.
Question 2
In Python, what is a database “cursor” most like?
✅ A file handle
❌ A method
❌ A function
❌ A dictionary
Explanation:
A cursor acts like a file handle that lets you send SQL commands and fetch rows — similar to reading lines from a file.
Question 3
What method do you call in an SQLite cursor object in Python to run an SQL command?
✅ execute()
❌ send()
❌ run()
❌ socket()
Explanation:
The execute() method runs a single SQL statement (like SELECT, INSERT, UPDATE, etc.) through the cursor.
Question 4
In the following SQL:
cur.execute('SELECT count FROM Counts WHERE org = ? ', (org, ))
what is the purpose of the “?”?
✅ It is a placeholder for the contents of the “org” variable
❌ Search wildcard
❌ Multiple boolean operator
❌ Syntax error
Explanation:
In SQLite (and most databases), ? is used as a parameter placeholder to safely insert variables into SQL (avoiding SQL injection).
Question 5
In the following Python code:
cur.execute('SELECT count FROM Counts WHERE org = ? ', (org, ))
row = cur.fetchone()
what is the value in row if no rows match the WHERE clause?
✅ None
❌ -1
❌ Empty list
❌ Empty dictionary