0
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)

Above are my given tables with columns and i want to create 3rd table names Record by using foreign key. This is my create 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),
);

but it is giving me error as " QLiteManager: Likely SQL syntax error: CREATE 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), ); [ near "FOREIGN": syntax error ] Exception Name: NS_ERROR_FAILURE Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement] ".

1
  • Just execute the correct CREATE TABLE statement. What is the problem? Commented Aug 4, 2014 at 9:32

2 Answers 2

1

Some errors in the syntax:

  • Add a , before the first FOREIGN KEY table constraint.

  • Remove the , before the closing ) paren.

Sign up to request clarification or add additional context in comments.

Comments

0

after you define your attribut, add this following code

FOREIGN KEY (colonne_name) REFERENCES parent_table_name(colonne_name)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.