UPDATE-SET 语句用于更新表格内的任何列。以下 SQL 查询用于更新列。

>  update Employee set name = 'alex' where id = 110  

考虑以下示例。

示例

import mysql.connector  
  
#Create the connection object   
myconn = mysql.connector.connect(host = "localhost", user = "root",passwd = "google",database = "PythonDB")  
  
#creating the cursor object  
cur = myconn.cursor()  
  
try:  
    #updating the name of the employee whose id is 110  
    cur.execute("update Employee set name = 'alex' where id = 110")  
    myconn.commit()  
except:  
      
    myconn.rollback()  
  
myconn.close()  

80.png

删除操作

DELETE FROM 语句用于从表格中删除特定记录。在这里,我们必须使用 WHERE 子句强加条件,否则将删除表格中的所有记录。

以下 SQL 查询用于从表格中删除 id 为 110 的员工详细信息。

>  delete from Employee where id = 110  

考虑以下示例。

示例

import mysql.connector  
  
#Create the connection object   
myconn = mysql.connector.connect(host = "localhost", user = "root",passwd = "google",database = "PythonDB")  
  
#creating the cursor object  
cur = myconn.cursor()  
  
try:  
    #Deleting the employee details whose id is 110  
    cur.execute("delete from Employee where id = 110")  
    myconn.commit()  
except:  
      
    myconn.rollback()  
  
myconn.close()  

标签: Tkinter教程, Tkinter安装, Tkinter库, Tkinter入门, Tkinter学习, Tkinter入门教程, Tkinter, Tkinter进阶, Tkinter指南, Tkinter学习指南, Tkinter进阶教程, Tkinter编程