This function returns the file identification (ID) number for the specified logical name of a data, log, or full-text file of the current database.
Transact-SQL Syntax Conventions
FILE_IDEX ( file_name )
file_name
An expression of type sysname that returns the file ID value ‘FILE_IDEX’ for the name of the file.
int
NULL on error
file_name corresponds to the logical file name displayed in the name column from the sys.master_files or sys.database_files catalog views.
Use FILE_IDEX
in a SELECT list, a WHERE clause, or anywhere that supports use of an expression. For more information, see Expressions (Transact-SQL).
This example returns the file ID for the AdventureWorks_Data
file.
Here is the result set.
File ID
-------
1
(1 row(s) affected)
This example returns the file ID of the AdventureWorks
log file. The Transact-SQL (T-SQL) code snippet selects the logical file name from the sys.database_files
catalog view, where the file type equals 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
This example returns the file ID of a full-text file. The T-SQL code snippet selects the logical file name from the sys.database_files
catalog view, where the file type equals 4
(full-text). This code returns ‘NULL’ if a full-text catalog does not exist.
Metadata Functions (Transact-SQL)
sys.database_files (Transact-SQL)
sys.master_files (Transact-SQL)