获取给定模式的所有索引信息 - db2 [英] Get all the index information for a given schema -- db2

查看:267
本文介绍了获取给定模式的所有索引信息 - db2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个JDBC程序来获取一些数据库元数据信息,作为我想查询给定模式中所有索引的一部分。
我看了一些JDBC API,从 DatabaseMetaData 接口,可以使用 getTables 之类的方法来获取给定模式的所有表。我正在尝试找到类似的东西(或使用一些API的组合)来获取信息,如所有索引,视图等在模式上。有办法得到它吗?例如,对于索引,有一个方法 - getIndexInfo ,但是对于模式中的每个表,我需要调用此方法。我的数据库是db2。

解决方案

我会使用 DB2 Catalog Views 获取信息。



作为一个例子,如果你想要一个表的所有索引,你会使用这样的查询(我假设你在Linux / Unix / Windows这里):

  SELECT * 
FROM SYSCAT.INDEXES
WHERE tabname = @tablename
AND tabschema = @schema
ORDER BY indname


I am writing a JDBC program to fetch some database meta data information and as part of that I want to query all the indexes that are there in a given schema. I had a look at some JDBC API and from DatabaseMetaData interface, can use methods like getTables to get all the tables for a given schema. I am trying to find something similar (or write using a combination of some API) to get information like all the indexes,views etc on a schema. Is there a way to get it? For ex, for index there is a method - getIndexInfo but for each of the table in a schema, I need to call this method. My database is db2.

解决方案

I would use the DB2 Catalog Views to get the information.

As an example, if you want all of the indexes for a table, you'd use a query like this (I'm assuming you're using DB2 on Linux/Unix/Windows here):

SELECT *
FROM SYSCAT.INDEXES
WHERE tabname   = @tablename 
  AND tabschema = @schema
ORDER BY indname

这篇关于获取给定模式的所有索引信息 - db2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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