How to Get Primary Key and Unique Constraint Columns in Derby

若如初见. 提交于 2019-12-11 00:28:29

问题


How does one do this? The SYSCOLUMNS system table only has columns for tables. SYSCHECKS has a REFERENCEDCOLUMNS object. Is there any way to get this.

I'm aware of the JDBC getPrimaryKeys call, but that doesn't get unique constraint columns.


回答1:


Derby - constraints

It took some digging to find the above question; my question is a partially answered follow-up question to the one above.

Taking the CONSTRAINTID against SYSKEYS gives a CONGLOMERATEID, which when taken against SYSCONGLOMERATES yields a DESCRIPTOR. The DESCRIPTOR is a POJO that contains an int-array in the baseColumnPositions method. This int-array contains the COLUMNNUMBERS in SYSCOLUMNS of the columns in the constraint.

If querying in straight SQL, getting the DESCRIPTOR field yields a string with a CSV list of ints that have to be parsed. Fortunately for me, I happen to be working in Clojure, so calling the baseColumnPositions method and using the resulting int-array are trivial.



来源:https://stackoverflow.com/questions/2349785/how-to-get-primary-key-and-unique-constraint-columns-in-derby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!