我想创建一个全文索引,但我不确定所有数据库中的索引名称是否相同。所以,我打算写下面的select并得到索引的名称。
DECLARE @keyIndex NVARCHAR(100)
SELECT @keyIndex = name FROM sysobjects WHERE xtype = 'PK' AND parent_obj = OBJECT_ID(N'[dbo].[Table1]')
下面是我尝试过的全文索引的Create语句:
CREATE FULLTEXT INDEX ON dbo.Table1
(
[Name] Language 1033,
[Description] Language 1033
)
KEY INDEX [@keyIndex]
WITH STOPLIST = SYSTEM, CHANGE_TRACKING AUTO;
它给出了这个错误:
Msg 7653, Level 16, State 1, Line 11
'@keyIndex' is not a valid index to enforce a full-text search key. A full-text search key must be a unique, non-nullable, single-column index which is not offline, is not defined on a non-deterministic or imprecise nonpersisted computed column, does not have a filter, and has maximum size of 900 bytes. Choose another index for the full-text key.
我需要一些关于如何动态插入密钥索引值的帮助。
答案 0 :(得分:0)
手动构建字符串,然后执行它:
DECLARE @SQLString nvarchar(1000)
DECLARE @ParmDefinition nvarchar(1000)
DECLARE @keyIndex nvarchar(100);
set @keyIndex = 'Id'
SET @SQLString =
N'CREATE FULLTEXT INDEX ON dbo.objects
(
[Name] Language 1033,
[Description] Language 1033
)
KEY INDEX ' + @keyIndex +N'
WITH STOPLIST = SYSTEM, CHANGE_TRACKING AUTO;';
EXEC(@SQLString)