SQL查询以获取sybase ase 15.x中所有表的主键以及列名称 [英] SQL query to get primary keys for all tables in sybase ase 15.x along with column names

查看:2272
本文介绍了SQL查询以获取sybase ase 15.x中所有表的主键以及列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Sybase ASE 15.5和这个数据库的陌生人。
直接到 - >
我正在寻找一个sql查询,这将帮助我获得sybase中的所有表的主键以及主键被声明的列名称。
例如,
如果我有以下表,
组织在列org_id上具有主键PK_org_id
org_alias在列alias_id
上具有主键PK_alias_id具有org_temp的列上的主键PK_org_temp_id(org_id,org_name)

I'm using Sybase ASE 15.5 and a stranger to this database. Straight to the point--> I'm looking for a sql query that would help me get the primary keys for all tables in sybase along with the column names on which the primary key is declared. For example, if I have the following tables, organization having primary key PK_org_id on the column org_id org_alias having primary key PK_alias_id on the column alias_id org_temp having primary key PK_org_temp_id on the columns (org_id,org_name)

那么查询应返回我:


  • Table_Name PK_Name Column_name

  • 组织PK_org_id org_id

  • Org_alias PK_alias_id alias_id

  • Org_temp PK_org_temp_id org_id,org_name

  • Table_Name PK_Name Column_name
  • Organization PK_org_id org_id
  • Org_alias PK_alias_id alias_id
  • Org_temp PK_org_temp_id org_id,org_name

我尝试了以下查询:

select  o.name , i.name
from   sysobjects  o,   sysindexes   i   
where o.id=i.id  
and i.indid = 1  
and o.type = 'U'

但它只返回表名称及其主键。

but it only returns me the table name with its primary key. I want to have the column name too.

请帮助!

推荐答案

如果您不想对自己的查询进行编码,请查看ASE中包含的目录过程。 'sp_pkeys'应该给你你想要的。

If you don't want to code your own query, then look at the catalog procedures that are included with ASE. 'sp_pkeys' should give you what you want.

这篇关于SQL查询以获取sybase ase 15.x中所有表的主键以及列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆