We can drop a table in MySQL using the DROP
table statement.
The basic syntax of the drop table is,
DROP [TEMPORARY] TABLE [IF EXISTS] tbl_name [, tbl_name] ... [RESTRICT | CASCADE]
Users need to have the DROP privilege to be able to drop a table.
USE
statement.
show tables;
drop table <table-name> or <list of comma-separated table-names>
DROP table performance;
For example, the emp_id column of the "employees" table is a foreign key in the "employee_dept" table. If we try to drop the employees directly, we get the error shown in the screenshot below.
drop table employees;
Create TEMPORARY TABLE MAX_SALARY
SELECT E.FIRST_NAME,E.LAST_NAME,TEMP.SALARY,ED.DEPT_ID,D.DEPT_NAME FROM
(SELECT MAX(SALARY) AS 'SALARY', DEPT_ID FROM EMPLOYEES E, EMPLOYEE_DEPT ED WHERE E.EMP_ID = ED.EMP_ID GROUP BY ED.DEPT_ID) AS TEMP
INNER JOIN EMPLOYEE_DEPT ED ON TEMP.DEPT_ID = ED.DEPT_ID
INNER JOIN EMPLOYEES E ON E.EMP_ID = ED.EMP_ID AND TEMP.SALARY = E.SALARY
INNER JOIN DEPARTMENTS D ON D.DEPT_ID = ED.DEPT_ID;
DROP TEMPORARY TABLE <table_name>;
DROP TEMPORARY TABLE MAX_SALARY;