SA0218 : The '::' function calling syntax is deprecated
Introduction
Section titled “Introduction”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
Section titled “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:
-- Example of deprecated function callSELECT ::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 callSELECT 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
Section titled “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:
-- Example of deprecated function callSELECT ::fn_virtualfilestats(1, 1);
-- Recommended function callSELECT sys.fn_virtualfilestats(1, 1);The rule has a Batch scope and is applied only on the SQL script.
Parameters
Section titled “Parameters”Rule has no parameters.
Remarks
Section titled “Remarks”The rule does not need Analysis Context or SQL Connection.
Effort To Fix
Section titled “Effort To Fix”3 minutes per issue.
Categories
Section titled “Categories”Deprecated Features, Bugs
Additional Information
Section titled “Additional Information”Deprecated Database Engine Features in SQL Server 2017
Example Test SQL
Section titled “Example Test SQL”-- Deprecated syntax usage.SELECT * FROM ::fn_virtualfilestats(2,1)
-- Correct function call syntax.SELECT * FROM sys.fn_virtualfilestats(2,1)Analysis Results
Section titled “Analysis Results”| Message | Line | Column | |
|---|---|---|---|
| 1 | SA0218 : The ‘::’ function calling syntax is deprecated. | 2 | 16 |