【发布时间】:2014-09-26 17:25:26
【问题描述】:
I am using sqlite tool of Mozilla Firefox to manage my database and i have to create a table in which i have to use foreign key . How to do that?
These are my tables,
Table Name:QuestionWithAnswer
Column_Name=Format:
Date=DATETIME(Primary Key),
Question=Text,
Answer=Text,
UserAnswer=Text,
isCorrext=Text.
Table Name:Question
Column_Name=Format:
Question_ID=Integer(Primary Key)
Question=Text
Table Name:Record
Column_Name=Format:
id=integer(Primary Key)
DatewithTime=DATETIME(foreign key from QuestionWithAnswer)
UserAnswer=TEXT
isCorrect=BOOl
Question_ID=integer(foreign key from Question)
以上是我给定的带有列的表,我想使用外键创建第三个表名记录。 这是我的创建 stmt
TABLE Records
(
id INTEGER PRIMARY KEY,
DateWithTime DATETIME,
UserAnswer TEXT,
isCorrect TEXT,
Question_ID TEXT
FOREIGN KEY(DateWithTime) REFERENCES QuestionWithAnswer(Date),
FOREIGN KEY(Question_ID) REFERENCES Question(question_ID),
);
但它给了我错误 " QLiteManager:可能的 SQL 语法错误:CREATE TABLE Records ( id 整数主键, 日期时间日期时间, 用户回答文本, 是正确的文本, Question_ID TEXT
外键(DateWithTime) 参考 QuestionWithAnswer(Date), FOREIGN KEY(Question_ID) REFERENCES Question(question_ID), ); [在“外国”附近:语法错误] 异常名称:NS_ERROR_FAILURE 异常消息:组件返回失败代码:0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement] "。
【问题讨论】:
-
只需执行正确的CREATE TABLE 语句。有什么问题?