21

您好我正在寻找一个查询,该查询能够使用 SQL Server 2008 在数据库中的所有表和列上找到全文索引。欢迎为此提供任何信息或帮助

4

3 回答 3

40

这是你如何得到它们

SELECT 
    t.name AS ObjectName, 
    c.name AS FTCatalogName ,
    i.name AS UniqueIdxName,
    cl.name AS ColumnName
FROM 
    sys.objects t 
INNER JOIN 
    sys.fulltext_indexes fi 
ON 
    t.[object_id] = fi.[object_id] 
INNER JOIN 
    sys.fulltext_index_columns ic
ON 
    ic.[object_id] = t.[object_id]
INNER JOIN
    sys.columns cl
ON 
        ic.column_id = cl.column_id
    AND ic.[object_id] = cl.[object_id]
INNER JOIN 
    sys.fulltext_catalogs c 
ON 
    fi.fulltext_catalog_id = c.fulltext_catalog_id
INNER JOIN 
    sys.indexes i
ON 
        fi.unique_index_id = i.index_id
    AND fi.[object_id] = i.[object_id];
于 2013-12-09T19:53:24.990 回答
11
select distinct
    object_name(fic.[object_id])as table_name,
    [name]
from
    sys.fulltext_index_columns fic
    inner join sys.columns c
        on c.[object_id] = fic.[object_id]
        and c.[column_id] = fic.[column_id]
于 2013-05-16T14:56:09.623 回答
3

我知道这是一个旧线程,但我现在才需要这个答案,并发现上面的Sadra Abedinzadeh 的答案很有用,但对我的需求有点不足,所以我想我会在这里发布另一个答案,这是对Sadra 答案的修改,包括带有全文索引的索引视图和一些额外的列信息:

use MyDatabaseName -- Modify here, of course

SELECT 
    tblOrVw.[name] AS TableOrViewName,
    tblOrVw.[type_desc] AS TypeDesc,
    tblOrVw.[stoplist_id] AS StopListID,
    c.name AS FTCatalogName ,
    cl.name AS ColumnName,
    i.name AS UniqueIdxName
FROM
(
    SELECT TOP (1000) 
        idxs.[object_id],
        idxs.[stoplist_id],
        tbls.[name],
        tbls.[type_desc]
      FROM sys.fulltext_indexes idxs
      INNER JOIN sys.tables tbls
      on tbls.[object_id] = idxs.[object_id]
    union all 
    SELECT TOP (1000) 
        idxs.[object_id],
        idxs.[stoplist_id],
        tbls.[name],
        tbls.[type_desc]
      FROM sys.fulltext_indexes idxs
      INNER JOIN sys.views tbls -- 'tbls' reused here to mean 'views'
      on tbls.[object_id] = idxs.[object_id]
) tblOrVw 
INNER JOIN sys.fulltext_indexes fi 
on tblOrVw.[object_id] = fi.[object_id] 
INNER JOIN 
    sys.fulltext_index_columns ic
ON 
    ic.[object_id] = tblOrVw.[object_id]
INNER JOIN
    sys.columns cl
ON 
        ic.column_id = cl.column_id
    AND ic.[object_id] = cl.[object_id]
INNER JOIN 
    sys.fulltext_catalogs c 
ON 
    fi.fulltext_catalog_id = c.fulltext_catalog_id
INNER JOIN 
    sys.indexes i
ON 
        fi.unique_index_id = i.index_id
    AND fi.[object_id] = i.[object_id];
于 2019-01-04T18:37:29.507 回答