广东省建设安全管理协会网站,国家城乡和建设厅特殊工种网站,人类命运共同体,文章优化软件Python语言基础——Python MySQL Drop Table 文章目录Python语言基础——Python MySQL Drop Table一、Python MySQL Drop Table一、Python MySQL Drop Table
删除表 您可以使用 “DROP TABLE” 语句来删除已有的表#xff1a; 实例 删除 “customers” 表#xff1a; import…Python语言基础——Python MySQL Drop Table 文章目录Python语言基础——Python MySQL Drop Table一、Python MySQL Drop Table一、Python MySQL Drop Table
删除表 您可以使用 “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)