World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
559 Learners
Neha Kumawat
a year 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',)]