简体   繁体   中英

mysql create multiple tables

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(
...
);

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

 DROP TABLE IF EXISTS Job;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM