SQL - @@TOTAL_ERRORS Function
The SQL @@TOTAL_ERRORS statistical function is used to retrieve the number of errors. It returns the total number of disk errors encountered by the SQL server instance since the SQL server last started. A disk error is an error when an operation lacks sufficient disk space, then might be the database engine throws an 1101 or 1105 error( or disk error).
Note − In SQL, not all write errors are encountered by SQL Server itself, some are also accounted for by this function as well. The occasional non-fatal write errors are handled by the server itself and those are not considered errors.
Syntax
Following is the syntax of the SQL @@TOTAL_ERRORS function −
@@TOTAL_ERRORS
Return type
The return type of this function is an INTEGER.
Parameters
It does not accept any parameters.
Return value
This function returns the number of disk errors.
Example
In the following example,we are using the SQL @@TOTAL_ERRORS function to retrieve the number of disk errors of this SQL server instance.
SELECT @@TOTAL_ERRORS AS Total_erros;
Output
The above program produces the following output −
+-------------+ | Total_erros | +-------------+ | 0 | +-------------+
Example
The following is another example of the SQL @@TOTAL_ERRORS function. You can also use the GETDATE() function to retrieve the number of disk errors until today since the SQL server last started.
SELECT GETDATE() AS Curr_date, @@TOTAL_ERRORS AS Total_disk_error;
Output
On executing the above program, it will produce the following output −
+-------------------------+------------------+ | Curr_date | Total_disk_error | +-------------------------+------------------+ | 2023-03-02 11:13:38.010 | 0 | +-------------------------+------------------+