我想知道表的索引是什么。我正在使用 ASE ISQL,我可以通过右键单击表并选择 DDL 来知道索引,但是,另一台机器上的开发人员对 sybase 不熟悉,我想知道他的数据库的索引(他使用ASE)。
有查询吗?
有许多不同的方法可以查看数据库中的索引。
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
此代码将生成代码索引:
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