gpt4 book ai didi

ios - 在sqlite中创建带有外键的表

转载 作者:行者123 更新时间:2023-11-29 02:46:04 25 4
gpt4 key购买 nike

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)

上面是我给定的带有列的表,我想使用外键创建第三个表名 Record。这是我创建的 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 语法错误:创建表记录( id 整数主键, 日期时间日期时间, 用户回答文本, 是正确的文本, Question_ID 文本

外键(DateWithTime)引用 QuestionWithAnswer(日期), 外键(问题_ID)引用问题(问题_ID),); [在“FOREIGN”附近:语法错误]异常名称:NS_ERROR_FAILURE异常消息:组件返回失败代码:0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]”。

最佳答案

语法中的一些错误:

  • 在第一个 FOREIGN KEY 表约束之前添加 ,

  • 删除 ) 结束括号前的 ,

关于ios - 在sqlite中创建带有外键的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25115278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com