Applies To: SQL Server 2014, SQL Server 2016 Preview
Returns the file identification (ID) number for the specified logical file name of the data, log, or full-text file in the current database.
Applies to: SQL Server (SQL Server 2008 through current version).
Is an expression of type sysname that represents the name of the file for which to return the file ID.
NULL on error
The following example returns the file ID of the AdventureWorks log file by selecting the logical file name from the sys.database_files catalog view where the file type is equal to 1 (log).
USE AdventureWorks2012; GO SELECT FILE_IDEX((SELECT TOP(1)name FROM sys.database_files WHERE type = 1))AS 'File ID'; GO
Here is the result set.
File ID ------- 2
The following example returns the file ID of a full-text file by selecting the logical file name from the sys.database_files catalog view where the file type is equal to 4 (full-text). This example will return NULL if a full-text catalog does not exist.