Skip to content

Latest commit

 

History

History
79 lines (62 loc) · 2.97 KB

file-id-transact-sql.md

File metadata and controls

79 lines (62 loc) · 2.97 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs
FILE_ID (Transact-SQL)
FILE_ID (Transact-SQL)
markingmyname
maghan
03/14/2017
sql
t-sql
reference
FILE_ID
FILE_ID_TSQL
IDs [SQL Server], files
file IDs [SQL Server]
FILE_ID function
names [SQL Server], files
identification numbers [SQL Server], files
file names [SQL Server], FILE_ID
TSQL

FILE_ID (Transact-SQL)

[!INCLUDE SQL Server Azure SQL Managed Instance]

For the given logical name for a component file of the current database, this function returns the file identification (ID) number.

Important

[!INCLUDEssNoteDepFutureAvoid] Use FILE_IDEX instead.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

FILE_ID ( file_name )  

Arguments

file_name
An expression of type sysname, representing the logical name of the file whose file ID value FILE_ID will return.

Return Types

smallint

Remarks

file_name corresponds to the logical file name displayed in the name column of the sys.master_files or sys.database_files catalog views.

FILE_ID returns NULL if file_name does not correspond to the logical name of a component file of the current database.

In [!INCLUDEssNoVersion], the file identification number assigned to full-text catalogs exceeds 32767. Because the FILE_ID function has a smallint return type, FILE_ID will not support full-text files. Use FILE_IDEX instead.

Examples

This example returns the file ID value for the AdventureWorks2022_Data file, a component file of the [!INCLUDE sssampledbobject-md] database.

USE AdventureWorks2022;  
GO  
SELECT FILE_ID('AdventureWorks2022_Data')AS 'File ID';  
GO  

[!INCLUDEssResult]

File ID   
-------   
1  
(1 row(s) affected)  

See Also

Deprecated Database Engine Features in SQL Server 2016
FILE_NAME (Transact-SQL)
Metadata Functions (Transact-SQL)
sys.database_files (Transact-SQL)
sys.master_files (Transact-SQL)