mysql creates multiple tables

advertisements

I'm working on a project in which i need to create two tables in one query.

I'm writing like this:

DROP TABLE Employee;

CREATE TABLE Employee(
Employee_Id CHAR(12)NOT NULL PRIMARY KEY,
First_name CHAR(30),
Last_name CHAR(30),
Address VARCHAR(50),
City CHAR,
State CHAR,
Salary INT,
Gender CHAR,
Age INT
);

DROP TABLE Job;

CREATE TABLE job(
Exempt_Non_Exempt_Status tinyint(1) NOT NULL PRIMARY KEY,
Job_title CHAR,
Job_description CHAR
);

But this gives an error like "Unknown table 'job'" even if I didn't create it.


Use the DROP Table IF EXISTS syntax:

Use IF EXISTS to prevent an error from occurring for tables that do not exist.

Something like:

DROP TABLE IF EXISTS
  Employee ;

CREATE TABLE Employee(
...
);

DROP TABLE IF EXISTS
  Job ;

CREATE TABLE Job(
...
);