1

テーブルのインデックスを知りたい。私はASE ISQLを使用しており、テーブルを右クリックしてDDLを選択することでインデックスを知ることができますが、別のマシンにsybaseに慣れていない開発者がいて、彼のデータベースのインデックスを知りたいです(彼が使用しているASE)。

そのためのクエリはありますか?

4

2 に答える 2

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
于 2013-05-22T12:35:55.103 に答える
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
于 2013-08-28T23:29:53.537 に答える