| |

VerySource

 Forgot password?
 Register
Search
View: 867|Reply: 5

When writing a program in SQL, how do you handle error? For example, similar to the on error goto err in vb?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-5 12:50:01
| Show all posts |Read mode
When writing a program in SQL, how do you handle error? For example, similar to the on error goto err in vb?
Write a stored procedure, how to handle error? There is no similar on error statement?
Reply

Use magic Report

1

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-5 16:15:01
| Show all posts
@@ error
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-1-6 02:15:01
| Show all posts
GOTO
Change execution flow to label.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-2-11 21:45:01
| Show all posts
It feels that the stored procedure in SQL, the syntax is not a facet object, do you think?
I don't know how SQL2005 has progressed in this regard, it has never been used.
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-13 11:15:01
| Show all posts
USE pubs
GO
DECLARE @tablename sysname
SET @tablename = N'authors'
table_loop:
   IF (@@ FETCH_STATUS <> -2)
   BEGIN
      SELECT @tablename = RTRIM (UPPER (@tablename))
      EXEC ("SELECT" "" + @tablename + "" "= COUNT (*) FROM"
            + @tablename)
      PRINT ""
   END
   FETCH NEXT FROM tnames_cursor INTO @tablename
IF (@@ FETCH_STATUS <> -1) GOTO table_loop
GO
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 United States

Post time: 2020-2-19 13:15:02
| Show all posts
@Error in SQL Server to determine if it is abnormal
E.g:
insert into table1 (a, b) select 'aaa', 'bbbb'
if @@ error <> 0 goto err

return 0

err:
  return 1
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list