帮我看看这段mysql代码的语法错误:CREATE TABLE borrow ( bookid INT NOT NULL, borrowerid INT NOT NULL, loan CHAR(4) DEFAULT '借' NULL, borrowerdata DATE NULL, PRIMARY KEY(bookid,borrowerid), CONSTRAINT fk_bookid FOREIGN KEY(bookid) REFERENCES books(bookid), CONSTRAINT fk_borrowerid FOREIGN(`borrowerid`) REFERENCES readers(borrowerid), INDEX borrowerdate_index(borrowerdate) );
时间: 2023-06-12 20:06:03 浏览: 160
mysql错误代码
这段MySQL代码有两个语法错误:
1. 在 `DEFAULT '借' NULL` 中,默认值和 `NULL` 之间不应该有逗号。应该改为 `DEFAULT '借'`.
2. 在第二个外键约束中,`FOREIGN(`borrowerid`)` 应该改为 `FOREIGN KEY(borrowerid)`。
下面是修改后的代码:
```
CREATE TABLE borrow (
bookid INT NOT NULL,
borrowerid INT NOT NULL,
loan CHAR(4) DEFAULT '借',
borrowerdata DATE NULL,
PRIMARY KEY(bookid,borrowerid),
CONSTRAINT fk_bookid FOREIGN KEY(bookid) REFERENCES books(bookid),
CONSTRAINT fk_borrowerid FOREIGN KEY(borrowerid) REFERENCES readers(borrowerid),
INDEX borrowerdate_index(borrowerdata)
);
```
注意,我还将 `INDEX borrowerdate_index(borrowerdate)` 修改为 `INDEX borrowerdate_index(borrowerdata)`,因为列名应该与定义保持一致。
阅读全文