2

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.

2
  • 2
    Do the tables exist before you try to drop them? Commented Nov 19, 2011 at 7:27
  • 1
    @Adi, you can also use CREATE TABLE IF NOT EXISTS Commented May 8, 2015 at 7:53

2 Answers 2

8

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(
...
);
Sign up to request clarification or add additional context in comments.

Comments

2

You cant drop a table that doesnt exist. Use the:

 DROP TABLE IF EXISTS Job;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.