![](/img/trans.png)
[英]I am trying to use MYSQL SELECT with many-to many relationship tables?
[英]MySQL many-to many relationship
無法創建最后一個表:(在我看來,答案應該非常簡單,但不幸的是找不到它。這是代碼:
CREATE TABLE Topics ( topicId INT NOT NULL AUTO_INCREMENT,
topicName VARCHAR(50) NOT NULL,
submdate DATE NOT NULL,
accdate DATE NOT NULL,
comm VARCHAR(100),
status varchar(1) CHECK (status>0 and status<4),
PRIMARY KEY (topicId) );
CREATE TABLE Student ( studentId INT NOT NULL AUTO_INCREMENT,
studentname VARCHAR(50) NOT NULL,
PRIMARY KEY (studentId) );
CREATE TABLE TopicStudent ( topicId INT NOT NULL,
studentId INT NOT NULL,
PRIMARY KEY (topicId, studentId),
CONSTRAINT Constr_TopicStudent_Student_fk
FOREIGN KEY Student_fk (studentId) REFERENCES Student (studentId)
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT Constr_TopicStudent_Topic_fk
FOREIGN KEY Topic_fk (topicId) REFERENCES Topic (topicId)
ON DELETE CASCADE ON UPDATE CASCADE
);
錯誤1064(42000):您的SQL語法有錯誤; 在第1行的“ Const r_TopicStudent_Student_fk FOREIGN KEY Student_fk(studentId)參考Stu”附近,查看與您的MySQL服務器版本相對應的手冊以使用正確的語法。
Const r_TopicStudent
? “ Const”和“ r_TopicStudent”之間是否有空格?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.