World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITian's, only for AI Learners.
Download our e-book of Introduction To Python
4 (4,001 Ratings)
218 Learners
Neha Kumawat
5 months ago
DROP TABLE table_name;
mysql> SHOW TABLES;
+-----------------+
| Tables_in_mydb |
+-----------------+
| contact |
| cricketers_data |
| employee |
| sample |
| tutorials |
+-----------------+
5 rows in set (0.00 sec)
mysql> DROP TABLE sample;
Query OK, 0 rows affected (0.29 sec)
mysql> SHOW TABLES;
+-----------------+
| Tables_in_mydb |
+-----------------+
| contact |
| cricketers_data |
| employee |
| tutorials |
+-----------------+
4 rows in set (0.00 sec)
import mysql.connector
#establishing the connection conn = mysql.connector.connect(
user='root', password='password', host='127.0.0.1', database='mydb'
)
#Creating a cursor object using the cursor() method cursor = conn.cursor()
#Retrieving the list of tables print("List of tables in the database: ")
cursor.execute("SHOW Tables") print(cursor.fetchall())
#Doping EMPLOYEE table if already exists cursor.execute("DROP TABLE EMPLOYEE")
print("Table dropped... ")
#Retrieving the list of tables print(
"List of tables after dropping the EMPLOYEE table: "
)
cursor.execute("SHOW Tables") print(cursor.fetchall())
#Closing the connection
conn.close()
List of tables in the database:
[('employee',), ('employeedata',), ('sample',), ('tutorials',)]
Table dropped...
List of tables after dropping the EMPLOYEE table:
[('employeedata',), ('sample',), ('tutorials',)]
mysql.connector.errors.ProgrammingError: 1051 (42S02): Unknown table 'mydb.employee'
import mysql.connector
#establishing the connection
conn = mysql.connector.connect(
user='root', password='password', host='127.0.0.1', database='mydb'
)
#Creating a cursor object using the cursor() method
cursor = conn.cursor()
#Retrieving the list of tables
print("List of tables in the database: ")
cursor.execute("SHOW Tables")
print(cursor.fetchall())
#Doping EMPLOYEE table if already exists
cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
print("Table dropped... ")
#Retrieving the list of tables
print("List of tables after dropping the EMPLOYEE table: ")
cursor.execute("SHOW Tables")
print(cursor.fetchall())
#Closing the connection
conn.close()
List of tables in the database:
[('employeedata',), ('sample',), ('tutorials',)]
Table dropped...
List of tables after dropping the EMPLOYEE table:
[('employeedata',), ('sample',),
('tutorials',)]