栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

查询以检查informix中的表上是否存在主键

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

查询以检查informix中的表上是否存在主键

首先寻找PK的索引名称(pk_idx列)

select c.constrname, c.constrtype as tp , c.idxname as pk_idx , t2.tabname, c2.idxnamefrom sysconstraints c, systables t, outer (sysreferences r, systables t2, sysconstraints c2)where t.tabname = "asamembr"  and t.tabid = c.tabid  and r.constrid = c.constrid  and t2.tabid = r.ptabid  and c2.constrid = r.constrid

其中的构造型:

constrtype CHAr(1) Code identifying the constraint type:
C = Check constraint
N = Not NULL
P = Primary key
R = Referential
T = Table
U = Unique


然后,检查索引列(查找与PK约束相同的索引名称):

   select unique        t.tabname      , i.idxname      , i.idxtype      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part1 )      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part2 )      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part3 )      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part4 )      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part5 )      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part6 )      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part7 )      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part8 )      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part9 )      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part10)      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part11)      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part12)      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part13)      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part14)      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part15)      , (select c.colname from syscolumns c where c.tabid = i.tabid and c.colno = i.part16)      from sysindexes i , systables t      where i.tabid = t.tabid        and t.tabname = "asamembr";

其中idxtype:

idxtype CHAr(1) Index type:
U = Unique
D = Duplicates allowed
G = Nonbitmap generali
g = Bitmap generalized
u = unique, bitmap
d = nonunique, bitmap

在Informix在线手册中搜索“
sysconstraints”或“ sysindexes”



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/410907.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号