SQLite Forum

Main Topic and Non Main Topics (Was: Topic and subtopic)
Login
Not having good names makes it harder to talk about such things, so let me define a few things.

A table Topic, with a Primary Key of topicID.

A second table Record, with a Primary Key of recordID, another field topicID which has (at least effectively) a Foreign Key constraint to Topic.topicID

A third table Link which has fields recordID and topicID, which are (effectively) Foreign Keys to the above table.

Your constraint is effectivly that you never want the topicID in a record of the Link Table to match the topicID in the matching row of Record as specified by recordID. This basically by definition requires doing a JOIN on the Link and Record tables to test, and I am not sure if there is any way to define a constraint that would automatically do this join to make the test, as it would be somewhat expensive to do in general.