单选题 适中
#5726

运行以下代码输出的数据为?() import sqlite3 connection = sqlite3 . connect ( "students.db" )…

运行以下代码输出的数据为?()

import sqlite3
connection=sqlite3.connect("students.db")
cursor=connection.cursor()
cursor.execute("CREATE TABLE students(name TEXT,age INTEGER)")
cursor.execute("INSERT INTO students VALUES('John',19)")
cursor.execute("INSERT INTO students VALUES('John',18)")
cursor.execute("DELETE FROM students WHERE name='John'")
cursor.execute("INSERT INTO students VALUES('John',17)")
cursor.execute("UPDATE students SET age=22 WHERE name='John'")
cursor.execute("SELECT*FROM students")
results=cursor.fetchall()
for row in results:
    print(row)
connection.close()
未登录也能判分,登录后才会记录
答案与解析
正确答案:A
解析

创建了数据库和表之后,插入了二条姓名都为'John'数据,然后删除'John'相关数据时二条数据都被删除,重新插入'John'的数据并修改为 22,故最后查找出的结果为 22。