我需要将 2 个 sqlite 表(例如 id1 和 id2)的主键关联起来,以便 id1 不能等于任何 id2,反之亦然。这是因为我需要从这两个表中获取相同类型的 xml 元素,并具有唯一的属性 id。
有没有一种方法可以在 sqlite 理解的 sql 中或在“经典”sql 中表达对我的 id 字段的此类约束?
或者,我想我可以参考其他 2 个表和唯一 id 创建另一个表,从中获取数据...但我想知道是否可以先以其他方式进行,以及哪个是您认为这种情况下的最佳实践。
谢谢你!
I need the primary keys of 2 sqlite tables (say, id1 and id2) to be related such that no id1 can be equal to any id2 and viceversa. This is because I need to obtain from these 2 tables the same type of xml element, with unique attribute id.
Is there a way either in sql as understood by sqlite or in "classic" sql to express such constraints to my id fields?
Alternatively, I guess I could create another table with reference to the other 2 and unique id from which I'd take my data... but I'd like to know if it is possible in the other way first, and which is the best practice in this case in your opinion.
Thank you!
发布评论
评论(1)
从技术上讲,XML ID 值无论如何都不能是数字,因此在存储到 XML 之前,请在 id 前面添加文本。那么你就不必担心数字重复。
http://www.w3.org/TR/2004 /REC-xml-20040204/#NT-名称
XML ID values technically can't be numbers anyways, so prepend the id with text before storing in XML. Then you don't need to worry about numeric duplicates.
http://www.w3.org/TR/2004/REC-xml-20040204/#NT-Name