PhpMyAdmin - SQL创建表错误#1064

时间:2016-12-08 19:23:16

标签: mysql phpmyadmin

我试图创建一些表,它们之间有一对多的关系。我得到这个错误,我已经读过其他帖子,并怀疑它与FK有关。任何帮助都会很棒! :D谢谢

我在XAMPP服务器上使用PhpMyAdmin。我创建了数据库,单击了SQL选项卡,然后将我的代码放入其中。我收到了以下错误。

错误:

Error
Static analysis:

2 errors were found during analysis.

Unexpected beginning of statement. (near "userID" at position 307)
Unrecognized statement type. (near "INT" at position 314)
SQL query:

CREATE TABLE reportTable ( reportID INT AUTO_INCREMENT, submitDate DATETIME, submitBy VARCHAR(255), reportInformation VARCHAR(255), reviewedBy VARCHAR(255), PRIMARY KEY(reportID), FOREIGN KEY(userID) REFERENCES userTable(userID) ) CREATE TABLE userTable ( userID INT AUTO_INCREMENT, username VARCHAR(255), PRIMARY KEY(userID) )

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE TABLE userTable (
    userID INT AUTO_INCREMENT,
    username VARCHAR(2' at line 11

代码:

CREATE TABLE reportTable (
    reportID INT AUTO_INCREMENT,
    userID INT,
    submitDate DATE,
    submitBy VARCHAR(255),
    reportInformation VARCHAR(255),
    reviewedBy VARCHAR(255),
    PRIMARY KEY(reportID),
    FOREIGN KEY(userID) REFERENCES userTable(userID)
);

CREATE TABLE userTable (
    userID INT AUTO_INCREMENT,
    username VARCHAR(255),
    PRIMARY KEY(userID)
);

1 个答案:

答案 0 :(得分:1)

正如我在评论中提到的,分号通常用于结束陈述。否则,MySQL不知道你何时停止。在PHPMyAdmin中执行一个查询时,它将正确解释它,但不会在您执行多个语句时解释它。这将修复您的运行语句。

CREATE TABLE reportTable (
    reportID INT AUTO_INCREMENT,
    submitDate DATE,
    submitBy VARCHAR(255),
    reportInformation VARCHAR(255),
    reviewedBy VARCHAR(255),
    PRIMARY KEY(reportID),
    FOREIGN KEY(userID) REFERENCES userTable(userID)
);

CREATE TABLE userTable (
    userID INT AUTO_INCREMENT,
    username VARCHAR(255),
    PRIMARY KEY(userID)
);