5

In SQL Server I used the following code to drop a table with a constraint:

IF OBJECT_ID('EMPLOYEES') IS NOT NULL
  BEGIN
         ALTER TABLE EMPLOYEES DROP CONSTRAINT EMP_DEPT_FK
         DROP TABLE EMPLOYEES;
  END

How can I accomplish the same thing in Mysql?

Joe Obbish
  • 32,976
  • 4
  • 74
  • 153
andrea
  • 341
  • 1
  • 6
  • 14

1 Answers1

5

You can use information_schema to check if the table exists but in MySQL there is a simpler method:

DROP TABLE IF EXISTS employees ;
ypercubeᵀᴹ
  • 99,450
  • 13
  • 217
  • 306