2013-05-22 109 views
1

我想知道什麼是表的索引。我正在使用ASE ISQL,通過右鍵單擊表並選擇DDL,我可以知道索引,但是,在另一臺機器中有一位開發人員對他不熟悉的sybase,我想知道他的數據庫的索引(他正在使用ASE)。是否有查詢索引?

是否有查詢?

回答

2

有許多不同的方式來查看數據庫中的索引。

sp_helpindex可用於顯示與特定表關聯的索引。

sp_helpindex TABLE_NAME 

sp_help可用於列出表格的所有屬性,包括關聯的索引。

sp_help TABLE_NAME 

要獲得所有指標及其關聯表的列表,你可以使用下面的查詢

use DATABASE_NAME 
go 

select sysobjects.name as TABLE_NAME, sysindexes.name as INDEX_NAME 
from sysobjects,sysindexes where 
sysobjects.type = 'U' and 
sysobjects.id = sysindexes.id and 
sysindexes.indid between 1 and 254 
order by sysobjects.name,sysindexes.indid 
go 
+0

感謝名單你很多,我不能因爲我的代表低而投票給你,但你無力地幫助我 – Moudiz

2

此代碼將生成代碼指標:

use [database] 
go 
declare @objectName sysname 
declare @username sysname 
declare @fullname sysname 
declare @id int 

select 
    @id = o.id, 
    @objectName = o.name, 
    @username = u.name, 
    @fullname = u.name + '.' + o.name 
from 
    dbo.sysobjects o, 
    dbo.sysusers u 
where 
    o.name = 'Table' 
    and o.Type in ('U', 'S') 
    and u.uid = o.uid 
    and u.name = 'Owner' 

select 
    [index] = 1000 * i.indid, 
    text = 
    'create' + 
    case i.status & 2 
     when 2 then ' unique ' 
     else ' ' 
    end + 
    case (i.status & 16) + (i.status2 & 512) 
     when 0 then 
     'nonclustered' 
     else 
     'clustered' 
    end + 
    ' index [' + i.name + '] on ' + @fullname + ' (' 
from 
    dbo.sysindexes i 
where 
    i.indid > 0 
    and i.indid < 255 
    and i.id = @id 
    and i.status2 & 2 != 2 

union all 

select 
    [index] = 1000 * i.indid + c.colid, 
    text = 
    ' ' + index_col (@fullname, i.indid, c.colid) + 
    case 
    when c.colid < i.keycnt - case when i.indid = 1 then 0 else 1 end then 
     ', ' 
    end 
from 
    dbo.sysindexes i, 
    dbo.syscolumns c 
where 
    i.indid > 0 
    and i.indid < 255 
    and i.id = @id 
    and i.status2 & 2 != 2 

    and c.id = @id 
    and c.colid <= i.keycnt - case when i.indid = 1 then 0 else 1 end 

union all 

select 
    [index] = 1000 * i.indid + 999, 
    text = 
    ')' || char (13) || char (10) || 'go' || char (13) || char (10) 
from 
    dbo.sysindexes i 
where 
    i.indid > 0 
    and i.indid < 255 
    and i.id = @id 
    and i.status2 & 2 != 2 

order by 
    [index] 
go 
相關問題