我有两个现有的表,workTable和table_jobs。我想更新我的workTable并使用默认值创建与table_jobs的关系。这就是我试过的:
ID | Value
-----------------------
1 | Bob
2 | Jane
3 | Bob
4 | Mike
5 | Suzy
6 | Mike
这给了我以下例外:
android.database.sqlite.SQLiteException:near" FOREIGN&#34 ;:语法错误(代码1):,编译时:ALTER TABLE工作对象添加列JobID INTEGER DEFAULT 1 FOREIGN KEY(JobID)REFERENCES Jobs(jobsID )
有什么问题?
答案 0 :(得分:1)
FOREIGN KEY子句是表约束。 ALTER TABLE不支持表约束。
您必须将外键约束设为列约束:
For i = 0 To 10000
ProdE = Rnd()
ProdF = Rnd()
ProdG = Rnd()
ProdH = Rnd()
ProdI = Rnd()
If ProdE <= 0.1 Then DaysLateE = 2
If 0.1 < ProdE <= 0.2 Then DaysLateE = 3
If 0.2 < ProdE <= 0.3 Then DaysLateE = 4
If 0.3 < ProdE <= 0.4 Then DaysLateE = 5
If 0.4 < ProdE <= 0.5 Then DaysLateE = 6
If 0.5 < ProdE <= 0.6 Then DaysLateE = 7
If 0.6 < ProdE <= 0.7 Then DaysLateE = 8
If 0.7 < ProdE <= 0.8 Then DaysLateE = 9
If 0.8 < ProdE <= 0.9 Then DaysLateE = 10
If 0.9 < ProdE <= 1 Then DaysLateE = 11
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
TotalDaysLateE = DaysLateE + 8
SumDaysLateE = SumDaysLateE + TotalDaysLateE
If TotalDaysLateE > 15 Then CountE = CountE + 1
End If
ALTER TABLE WorkObjects
ADD COLUMN JobID INTEGER DEFAULT 1 REFERENCES Jobs(jobsID);
好吧,好吧。你必须重新创建表。
答案 1 :(得分:0)
Here there is a well explained answer for this似乎只有在创建表时才能添加外键。您可以在新的临时表中移动数据,然后使用外键约束重新创建原始数据。