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?
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.
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