Skip to content

SA0218 : The '::' function calling syntax is deprecated

The usage of the deprecated built-in function calling syntax ::function_name() in T-SQL code can cause compatibility issues in future SQL Server versions.

This rule identifies and highlights the use of deprecated syntax for calling built-in functions in T-SQL code. The specific syntax involves using ::function_name() , which is an outdated practice in SQL Server.

The recommended approach is to use the sys.function_name() syntax. Continuing to use the deprecated method can lead to compatibility issues with newer SQL Server versions and reduce code maintainability.

For example:

-- Example of deprecated function call
SELECT ::fn_virtualfilestats(1, 1);

Using ::fn_virtualfilestats() can cause problems because this syntax is no longer supported in recent SQL Server versions. Instead, it is better to use:

-- Recommended function call
SELECT sys.fn_virtualfilestats(1, 1);
  • Using deprecated syntax can lead to errors during code execution or upgrades, as it might not be supported in future SQL Server releases.

  • Employing the updated syntax improves code readability and maintenance, as it aligns with current SQL Server standards and practices.

Update deprecated system function calls to ensure compatibility and maintainability.

Follow these steps to address the issue:

1.Identify all occurrences of system functions using the deprecated ::function_name() syntax in your T-SQL scripts.

2.Replace the deprecated syntax with the current sys.function_name() format to adhere to modern SQL Server standards.

3.Test the updated scripts to verify that they work correctly with the new syntax and perform as expected.

For example:

-- Example of deprecated function call
SELECT ::fn_virtualfilestats(1, 1);
-- Recommended function call
SELECT sys.fn_virtualfilestats(1, 1);

The rule has a Batch scope and is applied only on the SQL script.

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.

3 minutes per issue.

Deprecated Features, Bugs

Deprecated Database Engine Features in SQL Server 2017

-- Deprecated syntax usage.
SELECT * FROM ::fn_virtualfilestats(2,1)
-- Correct function call syntax.
SELECT * FROM sys.fn_virtualfilestats(2,1)
  Message Line Column
1 SA0218 : The ‘::’ function calling syntax is deprecated. 2 16

Analysis Rules