I have a SQL Server FILETABLE. I am NOT trying to do FULL TEXT searching. I have a query which uses the file_type column in the WHERE clause. The estimated execution plan suggests a new index. I have read elsewhere here on SO that one can create indexes for Filetables. However, I don't see that option in SSMS to do so through the GUI. So I tried via query, as below, but it doesn't seem to be created even though the execution says it was successful. Since there is no index folder under the filetable in question, where are indexes stored for this kind of table? And why isn't my index creation working? The estimated plan still says I need the same index I just tried to create.
CREATE NONCLUSTERED INDEX file_type
ON [dbo].[storedFiles] ([file_type])
INCLUDE ([stream_id],[path_locator])
GO
I have a SQL Server FILETABLE. I am NOT trying to do FULL TEXT searching. I have a query which uses the file_type column in the WHERE clause. The estimated execution plan suggests a new index. I have read elsewhere here on SO that one can create indexes for Filetables. However, I don't see that option in SSMS to do so through the GUI. So I tried via query, as below, but it doesn't seem to be created even though the execution says it was successful. Since there is no index folder under the filetable in question, where are indexes stored for this kind of table? And why isn't my index creation working? The estimated plan still says I need the same index I just tried to create.
CREATE NONCLUSTERED INDEX file_type
ON [dbo].[storedFiles] ([file_type])
INCLUDE ([stream_id],[path_locator])
GO
First, yes this is supported.
Since a FileTable has a pre-defined and fixed schema, you cannot add or change its columns. However, you can add custom indexes, triggers, constraints, and other options to a FileTable.
https://learn.microsoft.com/en-us/sql/relational-databases/blob/create-alter-and-drop-filetables?view=sql-server-ver16#BasicsAlter
You can see that the index was created with this query:
select object_name(i.object_id) tn, i.name index_name, c.name column_name, ic.key_ordinal, ic.is_included_column, i.index_id
from sys.indexes i
join sys.index_columns ic
on i.object_id = ic.object_id
and i.index_id = ic.index_id
join sys.columns c
on c.object_id = ic.object_id
and c.column_id = ic.column_id
where i.object_id = object_id('storedFiles')
Exec sp_help file_type
, see what comes back. – M.Ali Commented Jan 3 at 13:21