免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5464 | 回复: 10

已知表名和索引字段名,怎么得到该表的索引名? [复制链接]

论坛徽章:
0
发表于 2009-05-26 10:16 |显示全部楼层
5可用积分
已知:

1、表名:假设为A
2、该表的的某个索引(假设为IDX)的索引字段(AA,BB,CC)

怎样用Shell通过Informix的系统表得到这个IDX?

谢谢。

最佳答案

查看完整内容

因为在同一个索引里不太可能有两个相同的栏位,所以可以改成这样:select idxnamefrom sysindexes a,systables bwhere a.tabid = b.tabid and b.tabname='A' and a.part1 in (select colno from syscolumns c where c.tabid = b.tabid and c.colname in ("AA","BB","CC")) and a.part2 in (select colno from syscolumns c where c.tabid = b.tabid and ...

论坛徽章:
1
15-16赛季CBA联赛之江苏
日期:2017-04-05 11:23:15
发表于 2009-05-26 10:16 |显示全部楼层
因为在同一个索引里不太可能有两个相同的栏位,所以可以改成这样:
select idxname
from sysindexes a,systables b
where a.tabid = b.tabid and
     b.tabname='A' and
     a.part1 in (select colno from syscolumns c
                where c.tabid = b.tabid and
                      c.colname in ("AA","BB","CC")) and
     a.part2 in (select colno from syscolumns c
                where c.tabid = b.tabid and
                      c.colname in ("AA","BB","CC")) and
     a.part3 in (select colno from syscolumns c
                where c.tabid = b.tabid and
                      c.colname in ("AA","BB","CC"))

论坛徽章:
0
发表于 2009-05-26 11:09 |显示全部楼层

回复 #1 熊心搏搏 的帖子

查询这两个sysindexes 、sysindexkeys     表?

论坛徽章:
0
发表于 2009-05-26 12:38 |显示全部楼层
原帖由 ziggler 于 2009-5-26 11:09 发表
查询这两个sysindexes 、sysindexkeys     表?


谢谢,我知道是需要查询systabels,sysindexes,syscolumns表。关键是怎样查询?怎样的SQL?

论坛徽章:
0
发表于 2009-05-26 13:57 |显示全部楼层

回复 #3 熊心搏搏 的帖子

看看这几个表的结构和数据,就可以组织出SQL来了吧。

论坛徽章:
0
发表于 2009-05-26 14:10 |显示全部楼层
继续求助。。。

论坛徽章:
1
15-16赛季CBA联赛之江苏
日期:2017-04-05 11:23:15
发表于 2009-05-26 14:55 |显示全部楼层
写的比较笨,不过还是达到你的要求了,如果栏位多的话在后面再加a.part? , 给分!
select idxname
from sysindexes a,systables b
where a.tabid = b.tabid and
     b.tabname='A' and
     a.part1 = (select colno from syscolumns c
                where c.tabid = b.tabid and
                      c.colname = 'AA') and
     a.part2 = (select colno from syscolumns c
               where c.tabid = b.tabid and
                     c.colname = 'BB') and
     a.part3 = (select colno from syscolumns c
               where c.tabid = b.tabid and
                     c.colname = 'CC')

论坛徽章:
0
发表于 2009-05-26 15:10 |显示全部楼层
原帖由 yunzhongyue 于 2009-5-26 14:55 发表
写的比较笨,不过还是达到你的要求了,如果栏位多的话在后面再加a.part? , 给分!
select idxname
from sysindexes a,systables b
where a.tabid = b.tabid and
     b.tabname='A' an ...


谢谢,因为不能保证AA就是放在part1中,如果AA在part2中呢?只是知道是用AA,BB,CC这三个字段为索引,但是在表中到底是part1是AA,还是part2,part3是AA,是不知道的。因此,分暂不能给,不好意思。

[ 本帖最后由 熊心搏搏 于 2009-5-26 15:14 编辑 ]

论坛徽章:
0
发表于 2009-05-26 17:06 |显示全部楼层
原帖由 yunzhongyue 于 2009-5-26 16:10 发表
因为在同一个索引里不太可能有两个相同的栏位,所以可以改成这样:
select idxname
from sysindexes a,systables b
where a.tabid = b.tabid and
     b.tabname='A' and
     a.part1 in (select colno f ...


谢谢,这段代码依然有问题,假设表A有两个索引,一个以AA,BB,CC字段为索引,一个以AA,BB,CC,DD字段为索引。则按照上边的代码可能这两个索引名都会取出。但是我的要求是就只能取出AA,BB,CC字段为索引的索引名。

继续求助。。谢谢。。

论坛徽章:
0
发表于 2009-05-26 17:14 |显示全部楼层
改成这样应该可以的。
select idxname
from sysindexes a,systables b
where a.tabid = b.tabid and
     b.tabname='A' and
     a.part1 in (select colno from syscolumns c
                where c.tabid = b.tabid and
                      c.colname in ("AA","BB","CC")) and
     a.part2 in (select colno from syscolumns c
                where c.tabid = b.tabid and
                      c.colname in ("AA","BB","CC")) and
     a.part3 in (select colno from syscolumns c
                where c.tabid = b.tabid and
                      c.colname in ("AA","BB","CC")) and
     a.part4 = 0

[ 本帖最后由 熊心搏搏 于 2009-5-26 17:19 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP