当我们必须将MySQL与其他编程语言一起使用时, 可以使用连接器。 MySQL-connector的工作是提供对使用所需语言的MySQL驱动程序的访问。因此, 它在编程语言和MySQL Server之间生成了连接。
删除表命令
Drop命令影响表的结构而不影响数据。它用于删除已经存在的表。如果你不确定要删除的表是否存在如果存在则删除表使用命令。在以下示例中将处理这两种情况。
语法如下:
DROP TABLE tablename;
DROP TABLE IF EXISTS tablename;
以下程序将帮助你更好地理解这一点。
下降前的表:
文章图片
【Python MySQL 删除表用法指南】范例1:演示删除的程序(如果存在)。我们将尝试删除上述数据库中不存在的表。
# Python program to demonstrate
# drop clauseimport mysql.connector# Connecting to the Database
mydb = mysql.connector.connect(
host = 'localhost' , database = 'College' , user = 'root' , )cs = mydb.cursor()# drop clause
statement = "Drop Table if exists Employee"# Uncommenting statement ="DROP TABLE employee"
# Will raise an error as the table employee
# does not existscs.execute(statement)# Disconnecting from the database
mydb.close()
输出如下:
文章图片
范例2:程序放表极客
# Python program to demonstrate
# drop clauseimport mysql.connector# Connecting to the Database
mydb = mysql.connector.connect(
host = 'localhost' , database = 'College' , user = 'root' , )cs = mydb.cursor()# drop clause
statement = "DROP TABLE Geeks"cs.execute(statement)# Disconnecting from the database
mydb.close()
输出如下:
文章图片
注意怪胎!巩固你的基础Python编程基础课程和学习基础知识。
首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。
推荐阅读
- 算法(递归函数检查字符串是否是回文)
- 8086微处理器中的寻址模式详细指南
- 金融市场中的云计算服务简介
- 三星班加罗尔(SRIB)实习面试经验(校园内)
- 操作系统中目录的结构详细介绍
- SASS嵌套用法示例
- JavaScript面向对象的程序设计及原型链的理解运用全解【重点】
- JavaScript中的window对象属性方法全集
- JavaScript AJAX XMLHttpRequest对象的基本原理及用法全解