简体   繁体   English

mysql创建多个表

[英]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: 使用DROP Table IF EXISTS语法:

Use IF EXISTS to prevent an error from occurring for tables that do not exist. 使用IF EXISTS可以防止对不存在的表发生错误。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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