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.

Description

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:

SQL
1-- Example of deprecated function call
2SELECT ::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:

SQL
1-- Recommended function call
2SELECT 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.

How to fix

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:

SQL
1-- Example of deprecated function call
2SELECT ::fn_virtualfilestats(1, 1);
3
4-- Recommended function call
5SELECT sys.fn_virtualfilestats(1, 1);

Scope

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

Parameters

Rule has no parameters.

Remarks

The rule does not need Analysis Context or SQL Connection.

Effort To Fix
3 minutes per issue.
Categories

Deprecated Features, Bugs

Additional Information
Example Test SQL
SQL
1-- Deprecated syntax usage.
2SELECT * FROM ::fn_virtualfilestats(2,1) 
3
4-- Correct function call syntax.
5SELECT * FROM sys.fn_virtualfilestats(2,1)

Analysis Results
  Message Line Column
1 SA0218 : The ‘::’ function calling syntax is deprecated. 2 16
See Also

Other Resources