- mysql delete
- mysql update
删除表
您可以使用 "drop table" 语句来删除已有的表:
实例删除 "customers" 表:
import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", passwd="yourpassword", database="mydatabase" ) mycursor = mydb.cursor() sql = "drop table customers" mycursor.execute(sql)
运行实例
只在表存在时删除
如果要删除的表已被删除,或者由于任何其他原因不存在,那么可以使用 if exists 关键字以避免出错。
实例删除表 "customers" (如果存在):
import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", passwd="yourpassword", database="mydatabase" ) mycursor = mydb.cursor() sql = "drop table if exists customers" mycursor.execute(sql)
运行实例
- mysql delete
- mysql update
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!