我有一个简单的注册表单,它在“学生”表中创建了一条新记录:
cur = con.cursor()
query = "INSERT INTO students (Name, Address, Major, Phone, Email, Password) values (%s, %s, %s, %s, %s, %s)"
args = [name, address, major,phone, email, password]
cur.execute(query, args)
con.commit()
列 ID 是自动递增的,所以为了获得最后一个 ID,我选择 Max
query = "SELECT MAX(Id) FROM students;"
cur.execute(query)
id = cur.fetchone()[0]
它适用于我的小家庭作业项目,但如何在一个繁重的项目中完成,有可能在 select 语句之前创建一些东西?