问题描述
在 Sybase ASE 中,我想发现所有主键和唯一键.我想做一些类似于这个答案中解释的事情:
但不幸的是,这对我不起作用.不知何故,syskeys
表确实为我自己的键返回任何行,仅用于系统表键.
我可能做错了什么?一些缺少的赠款?我已经安装了 Sybase ASE 15.5 并且我正在与用户 dbo
连接,登录 sa
当您明确声明一个关键字段时 - 在 CREATE TABLE
语句中说 - 这不会填充 syskeys
表.您将使用(例如)sp_primarykeys
来做到这一点.这允许您在 syskeys
表中注册"您希望应用程序发现的主键、外键等.您可以通过这种方式声明主键,即使没有对相关字段强制实施实际约束.
存储过程 sp_helpconstraint
可用于查找为表定义的所有键(等).
要查询数据库中的所有表,您需要使用 sysindexes 表 并查看,例如status
字段.
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
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.
这篇关于发现 Sybase ASE 中的主键/唯一键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!