QuizzesSQLAlchemy — Python's Database Toolkit — Concept Check
intermediate
python

SQLAlchemy — Python's Database Toolkit — Concept Check

Questions on SQLAlchemy — Python's Database Toolkit. SQLAlchemy maps classes to tables (ORM), builds queries in Python (select/where/join), and manages transactions with Sessions — the standard DB layer under FastAPI apps.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on SQLAlchemy — Python's Database Toolkit — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A developer uses SQLAlchemy's ORM to map classes to tables. They notice some changes are not reflected in the database. What might they be forgetting?

    • AThey used the wrong database URL
    • BThey didn't use mapped_column
    • CThey didn't define primary keys
    • DThey forgot to call session.commit()
  2. 2.In SQLAlchemy, what is the purpose of the relationship() function?

    • ATo create database connections
    • BTo execute raw SQL queries
    • CTo handle joins and foreign keys as object navigation
    • DTo map classes to tables
  3. 3.A developer is using SQLAlchemy and notices that querying related objects results in multiple database queries. How can they optimize this?

    • ADisable foreign key constraints
    • BIncrease the session timeout
    • CUse selectinload to load related objects eagerly
    • DUse a different database engine
  4. 4.What happens if an exception occurs within a SQLAlchemy session block?

    • AThe transaction is automatically rolled back
    • BChanges are partially committed
    • CThe session is closed without rollback
    • DThe application crashes
  5. 5.A developer updates a student's CGPA in SQLAlchemy but doesn't see the change in the database. What might they have missed?

    • AUsing the correct data type for CGPA
    • BAdding the student to the session before update
    • CCalling session.commit() after the update
    • DDefining a primary key for the student
  6. 6.Why is SQLAlchemy's select() API considered safe against SQL injection?

    • AIt uses raw SQL strings
    • BIt parameterizes all queries
    • CIt requires manual query validation
    • DIt encrypts database connections
  7. 7.A developer needs to ensure that changes in a session are written to the database only if all operations succeed. How should they proceed?

    • ADisable autocommit mode
    • BCall commit after each operation
    • CUse raw SQL transactions
    • DUse a session block with a commit at the end
  8. 8.What is a potential cause of the N+1 query problem in SQLAlchemy?

    • AUsing parameterized queries
    • BLooping through objects and accessing related attributes
    • CDefining primary keys incorrectly
    • DUsing a single session for multiple transactions