gpt4 book ai didi

sql - 如何查明 Sybase 中的#table 上是否存在索引?

转载 作者:行者123 更新时间:2023-12-02 21:36:46 24 4
gpt4 key购买 nike

我正在使用 Sybase 15 SQL 存储过程。我想识别临时#table 上的索引。通常的技术适用于永久表,但不适用于临时表:

--look for an index on a temporary table

create table #T1( duff int)

create index idx99 on #T1(duff)

select * from sysindexes where name = 'idx99' --returns null rows !

--Look for an index on a permanent table

create table T1( duff int)

create index idx99 on T1(duff)

select * from sysindexes where name = 'idx99' --returns a row. OK for perm table.

有什么想法吗?

鲍勃

最佳答案

对于#tables,查找索引的查询与普通表相同,但需要针对 tempdb(或者 session 的临时数据库,如果它不是默认的)执行.

SELECT o.name, i.name
FROM tempdb..sysobjects o, tempdb..sysindexes i
WHERE o.id = i.id
AND o.name like "#T1%"
AND i.name like "idx99"

关于sql - 如何查明 Sybase 中的#table 上是否存在索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21188199/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com