1

これが私が作成している2つのテーブルの私のSQLです:

CREATE TABLE IF NOT EXISTS tbl_a(
    id INT(6) UNSIGNED NOT NULL,
    PRIMARY KEY(id)
)ENGINE = INNODB;

CREATE TABLE IF NOT EXISTS tbl_b(
    id INT(6) UNSIGNED NOT NULL,
    PRIMARY KEY(id),
    FOREIGN KEY id REFERENCES tbl_a(id) ON DELETE CASCADE ON UPDATE CASCADE
)ENGINE = INNODB;

これは私が得ているエラーです:

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 'REFERENCES a(id) ON DELETE CASCADE ON UPDATE CASCADE )ENGINE = INNODB' at line 4

誰かが私に解決策を提案してもらえますか?

4

1 に答える 1

1

()キー名を前後に追加します

CREATE TABLE IF NOT EXISTS tbl_b(
    id INT(6) UNSIGNED NOT NULL,
    PRIMARY KEY(id),
    FOREIGN KEY (id) REFERENCES tbl_a(id) ON DELETE CASCADE ON UPDATE CASCADE
)ENGINE = INNODB;
于 2012-11-27T10:12:49.647 に答える