Sybase
在 Sybase 中使用系統表來辨識表索引的列
是否有一種方法可以使用系統填充的系統表來辨識表索引的列,例如:
syscolumns
、sysindexes
、sysobjects
等。不幸的是,我嘗試使用
syskeys
此表僅由sp_primarykey
.到目前為止,我有以下查詢:
SELECT i.name, o.name FROM sysobjects o INNER JOIN sysindexes i on i.id = o.id WHERE o.type = 'U' and o.name = 'XXXXX' and i.indid > 0 and i.status & 2 = 2
我想出了以下解決方案 - 感謝 Phil 的評論:
SELECT distinct i.name as index_name, index_col(o.name, i.indid, c.colid) as name FROM sysobjects o INNER JOIN sysindexes i on i.id = o.id INNER JOIN syscolumns c on c.id = o.id WHERE o.type = 'U' and o.name = 'XXXXXX' and i.indid > 0 and i.status & 2 = 2 -- Gives only system indexes. Skip it, and get all and index_col(o.name, i.indid, c.colid) <> null order by 1, 2
為了某人的理智,munyengm 有這個正確的,但如果它不是 dbo 或您目前的使用者,您可能還需要傳遞對象所有者。
**SELECT distinct i.name as index_name, index_col(o.name, i.indid, c.colid, o.uid) as name FROM sysobjects o INNER JOIN sysindexes i on i.id = o.id INNER JOIN syscolumns c on c.id = o.id WHERE o.type = 'U' and o.name = 'XXXXXX' and i.indid > 0 and i.status & 2 = 2 and index_col(o.name, i.indid, c.colid, o.uid) <> null order by i.name**