我是MYSQL的新手,在MYSQL中我面临着一个非常简单的问题。我正在创建一个包含学生表的数据库,这个表包含学生的名字ID(主键)。我需要根据用户对id的选择(调用这个变量student_id)删除一个记录,那么如何使用python在mysql语句中编写这个记录呢?我试过了,但我知道这是错误的
cur.execute("Delete FROM students WHERE ID = student_id")发布于 2016-12-04 17:44:56
这应该适用于你:
student_id = int(input('Please, enter an ID: ')) # In Python 3, you need to parse the user input for numbers.
statmt = "DELETE FROM `students` WHERE id = %s"
cur.execute(statmt, (student_id,))
conn.commit() # You need to commit the transactionhttps://stackoverflow.com/questions/40961557
复制相似问题