发现 Sybase ASE 中的主键/唯一键
在 Sybase ASE 中,我想发现所有主键和唯一键。我想做一些类似于此答案中解释的操作:
但不幸的是,这对我不起作用。不知何故,syskeys
表确实返回了我自己的键的任何行,仅适用于系统表键。
我可能做错了什么?一些缺失的补助金?我已经安装了 Sybase ASE 15.5,并且正在与用户 dbo
连接,登录 sa
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您显式声明关键字段时(例如在 CREATE TABLE 语句中),此不会填充
syskeys
表。您可以使用(例如)sp_primarykeys
来执行此操作。这允许您在syskeys
表中“注册”您希望应用程序可发现的主键、外键等。即使没有对相关字段强制实施实际约束,您也可以通过这种方式声明主键。存储过程
sp_helpconstraint
可用于查找为表定义的所有键(等)。要查询数据库中的所有表,您需要使用 sysindexes 表 并查看,例如
status
字段。When you explicitly declare a key field - say in a
CREATE TABLE
statement - this doesn't populate thesyskeys
table. You would use (e.g.)sp_primarykeys
to do that. This allows you to 'register' in thesyskeys
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.