← Quiz: Checking AI-Written SQL: all 10 questions
Quiz: Checking AI-Written SQL · Question 8 of 10
Which is the safe way to use a user-typed name in a query?
Which is the safe way to use a user-typed name in a query?
- A.f"SELECT * FROM students WHERE name = '{name}'"
- B."SELECT * FROM students WHERE name = '" + name + "'"
- C.db.execute("SELECT * FROM students WHERE name = ?", (name,))
- D.Remove quotes from the name and paste it in
Answer & explanation
Correct answer: db.execute("SELECT * FROM students WHERE name = ?", (name,))
Parameters keep data separate from SQL code and prevent SQL injection.
Can you get the rest right without peeking?
Take the timed Quiz: Checking AI-Written SQL quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →