0
創建一個表我想這個查詢,儘管多次嘗試,我仍然得到一個語法錯誤,當我創建表調用。其他表獲得創建就好了。我不明白爲什麼語法錯誤,而在SQL
規範學生
CREATE TABLE Student (
`student_id` int NOT NULL AUTO_INCREMENT,
`phone_number` varchar(50) NOT NULL,
`name` varchar(50) NOT NULL,
`school` varchar(50) NOT NULL,
`class` varchar(50) NOT NULL,
PRIMARY KEY (`student_id`)
)
表故事
CREATE TABLE Stories (
`story_id` int NOT NULL AUTO_INCREMENT,
`story_name` varchar(50) NOT NULL,
`number_questions` int NOT NULL,
`file_name` varchar(100) NOT NULL,
PRIMARY KEY (`story_id`)
)
表問題
CREATE TABLE Questions (
`question_id` int NOT NULL,
`story_id` int NOT NULL,
`file_name` varchar(100) NOT NULL,
`concept_tested` varchar(100) NOT NULL,
`difficuly` varchar(50) NOT NULL,
`number_options` int NOT NULL,
`correct_answer` int NOT NULL,
`call_number` int NOT NULL,
PRIMARY KEY (`question_id`,`story_id`),
FOREIGN KEY (`story_id`)
REFERENCES `Stories`(`story_id`)
ON DELETE CASCADE
)
表調用
CREATE TABLE Call (
`call_id` int NOT NULL AUTO_INCREMENT,
`student_id` int NOT NULL,
`story_id` int NOT NULL,
`question_id` int NOT NULL,
`call_number` int NOT NULL,
`total_number` int NOT NULL,
PRIMARY KEY (`call_id`),
FOREIGN KEY (`student_id`)
REFERENCES `Student`(`story_id`)
ON DELETE CASCADE,
FOREIGN KEY (`story_id`)
REFERENCES `Stories`(`student_id`)
ON DELETE CASCADE,
FOREIGN KEY (`question_id`)
REFERENCES `Stories`(`question_id`)
ON DELETE CASCADE
)
這是我的錯誤:
#1064 - 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 'Call (`call_id` int NOT NULL AUTO_INCREMENT, `student_id` int NOT NULL, ' at line 1
我試圖編輯我的代碼,並檢查了好幾次,但問題仍然沒有解決
我解決了這個問題,
是:
CREATE TABLE `Call` (
`call_id` int NOT NULL AUTO_INCREMENT,
`student_id` int NOT NULL,
`story_id` int NOT NULL,
`question_id` int NOT NULL,
`call_number` int NOT NULL,
`total_number` int NOT NULL,
PRIMARY KEY (`call_id`),
FOREIGN KEY (`student_id`)
REFERENCES `Student`(`student_id`)
ON DELETE CASCADE,
FOREIGN KEY (`story_id`)
REFERENCES `Stories`(`story_id`)
ON DELETE CASCADE,
FOREIGN KEY (`question_id`)
REFERENCES `Questions`(`question_id`)
ON DELETE CASCADE
)
是它的mysql ** **或SQL服務器?不能同時存在......並更新錯誤的問題。 *語法錯誤*不是你得到的全部東西。 – MarcinJuraszek
顯示語法錯誤的任何錯誤消息? – tanghao
那些標記爲mysql ..不是sql server。我想操作只是困惑。 –