Discover primary / unique keys in Sybase ASE

房东的猫 提交于 2019-12-20 04:27:06

问题


In Sybase ASE, I would like to discover all primary and unique keys. I want to do something similar to what is explained in this answer:

Identifying Sybase tables, fields, keys, constraints

But unfortunately, this doesn't work for me. Somehow the syskeys table does return any rows for my own keys, only for system table keys.

What may I be doing wrong? Some missing grants? I have installed Sybase ASE 15.5 and I'm connecting with user dbo, login sa


回答1:


When you explicitly declare a key field - say in a CREATE TABLE statement - this doesn't populate the syskeys table. You would use (e.g.) sp_primarykeys to do that. This allows you to 'register' in the syskeys tables the primary, foreign keys, etc. that you would like to be discoverable by an application. You can declare a primary key in this way, even if there is no actual constraint enforced on the field in question.

The stored procedure sp_helpconstraint can be used to find all the keys (etc.) that are defined for a table.

To query for all tables in a database you'd need to use the sysindexes table and look at, e.g. the status field.



来源:https://stackoverflow.com/questions/7299550/discover-primary-unique-keys-in-sybase-ase

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