Goto statement : Goto « Transact SQL « SQL Server / T-SQL Tutorial






2>
3> CREATE TABLE a (
4> a char(1) primary key)
5>
6> CREATE TABLE b (
7> b char(1) references a)
8>
9> CREATE TABLE c (
10> c char(1))
11> GO
1>
2> CREATE PROC test as
3> BEGIN TRANSACTION
4> INSERT c VALUES ('X')
5>     IF (@@ERROR <> 0) GOTO on_error
6> INSERT b VALUES ('X')  -- Fails reference
7>     IF (@@ERROR <> 0) GOTO on_error
8> COMMIT TRANSACTION
9> RETURN(0)
10>
11> on_error:
12> ROLLBACK TRANSACTION
13> RETURN(1)
14>
15> GO








20.9.Goto
20.9.1.Using GOTO
20.9.2.Goto statement
20.9.3.IF @@ERROR <> 0 GOTO TRAN_ABORT