@@ERROR (TSQL Function)

Returns 0 if the last statement was executed successfully. Else, returns the error number.

In fact, @@ERROR always returns 0, because RSQL aborts the batch immediately when an error occurs.

Syntax

@@ERROR

Return Types

Returns int.

Remarks

@@ERROR is used abundantly in batches written for MS SQL Server.

RSQL implements @@ERROR only for compatibility with MS SQL Server, so that you can run batches written for MS SQL Server without having to delete the lines where it appears.

But with RSQL, @@ERROR always returns 0. If the previous statement encountered an error, RSQL rolls back and aborts the batch immediately.

So, RSQL behaviour is the same as MS SQL Server with the option XACT_ABORT ON.

There is no need to use @@ERROR when writing batches for RSQL.

Example:

CREATE TABLE t (a INT PRIMARY KEY NOT NULL, b VARCHAR(30));
GO

BEGIN TRANSACTION;

INSERT INTO t VALUES(10, 'hello');
INSERT INTO t VALUES(10, 'world');   --<--- duplicate key, RSQL aborts the batch and transaction is rolled back

COMMIT TRANSACTION;

PRINT 'Transaction successfully completed';

The result is:

<Duplicate key found, for constraint "$sysidx$0" in table "trashdb.dbo.t">