为什么mysql会给我一个错误?

时间:2016-04-25 19:50:10

标签: mysql node.js node-mysql

我使用带有node-mysql的node.js来执行我的查询。 这是我正在使用的代码:

var connection = mysql.createConnection(dbconfig.connection);

connection.query('CREATE DATABASE ' + dbconfig.database);
connection.query('USE '+ dbconfig.database);

connection.query('drop table if exists `ANSWER`; \
drop table if exists `ANSWERTYPE`; \
drop table if exists `COURSE`; \
drop table if exists `COURSEINSTANCE`; \
drop table if exists `ENROLL`; \
drop table if exists `FACULTY`; \
drop table if exists `QUESTION`; \
drop table if exists `QUESTIONGROUP`; \
drop table if exists `SEMESTER`; \
drop table if exists `STUDENTS`; \
drop table if exists `TEACHER`; \
........

但是节点继续显示错误:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'drop table if exists `ANSWERTYPE`; drop table if exists `COURSE`; drop table if ' at line 1

虽然我很确定我的查询是正确的,但我手动测试了它们。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

drop table的语法是:

DROP [TEMPORARY] TABLE [IF EXISTS] [/*COMMENT TO SAVE*/]
    tbl_name [, tbl_name] ...
    [RESTRICT | CASCADE]

所以你可以把一张桌子放在下一张桌子上

drop table if exists `ANSWER`, `ANSWERTYPE`, `COURSE`, `COURSEINSTANCE`; 

所以它只有一个陈述