ãã®åèªã¯ãTry ... Catchã³ã³ãããŒã«æ§é ãšçµã¿åãããŠäœ¿çšââã§ããå®è¡æãšã©ãŒã«é¢ããéç¥ãéä¿¡ã§ããŸãã äŸå€ãçºçãããšãããã°ã©ã ã¯ãäŸå€ãåŠçã§ããéå±€å ã®æãè¿ãCatchãããã¯ãæ€çŽ¢ããŸãã Catchãããã¯å ã§ãã®åŒã䜿çšãããšããšã©ãŒåºåãå€æŽã§ããŸãã ããã«ãã¹ã¯ãªããã®ä»»æã®å Žæã§äŸå€ãä»»æã«ã¹ããŒã§ããããã«ãªããŸããã
次ã«ãSQL ServerãããŒãžã§ã³2000ããããŒãžã§ã³2011ãŸã§æäŸããäŸå€ããã£ããããããŸããŸãªæ¹æ³ã«ã€ããŠãè³åŠäž¡è«ã亀ããŠèª¬æããŸãã
æ€èšäžã®ãã¹ãŠã®ã±ãŒã¹ã§ã tbl_ExceptionTestããŒãã«ã䜿çšãããŸãã
ããŠã¹ã§ãã¶ã€ããŒã«ç©Žãéããªãããã«ããããã«ã次ã®ã¹ã¯ãªãããå®è¡ããŠãç®çã®ããŒãã«ïŒèªåçæïŒãäœæã§ããŸãã
IF EXISTS (SELECT * FROM sys.objects WHERE name = 'tbl_ExceptionTest' AND type = 'U') DROP TABLE tbl_ExceptionTest GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tbl_ExceptionTest]( [Id] [int] IDENTITY(1,1) NOT NULL, [Phone Number] [int] NOT NULL, CONSTRAINT [PK_tbl_ExceptionTest] PRIMARY KEY CLUSTERED )
次ã«ãããã€ãã®ã¬ã³ãŒããããŒãã«ã«è¿œå ããé»è©±çªå·åã«äžé©åãªããŒã¿ãå ¥åãããšãã«äŸå€ãã¹ããŒããããšããŸãã
SQL Server 2000ïŒSphinxïŒã®ãšã©ãŒåŠç
ã°ããŒãã«å€æ°@@ ERRORã®äœ¿çš
SQL Server 2000ã䜿çšããŠããé ã«æ»ã£ãŠãå€æ°@@ Errorã®äœ¿çšã¯ããšã©ãŒãåŠçããæãé²æ©çã§å¹ççãªæ¹æ³ã§ãã£ãããšãæãåºããŠãã ããã ãã®å€æ°ã¯ãæåŸã«å®è¡ãããåŒã§çºçããæŽæ°ãšã©ãŒå€ãè¿ã圹å²ãæãããŸããã ãšã©ãŒå€ã¯æ£ãŸãã¯è² ã®ããããã§ããã0ã®ã¿ãæäœã®æåã瀺ããŠããŸãã ååŒã®å®è¡åŸã«å€æ°ã®å€ãå€æŽãããŸããã
ã¢ã¯ã·ã§ã³ã§@@ãšã©ãŒã䜿çšããŠèŠãŠã¿ãŸãããã
-- #tblExceptionTest , . If OBJECT_ID('tempdb..#tblExceptionTest') Is not null Begin Drop Table #tblExceptionTest End -- #tblExceptionTest Create Table #tblExceptionTest (Id int identity, [Phone Number] varchar(10) not null) -- Begin Transaction TranExcp__2000_@@Error -- -- @@ERROR Declare @ErrorNum int -- Declare @i int -- Set @i =1 -- While(@i <= 4) Begin -- null Phone Number If(@i = 4) Begin Insert into #tblExceptionTest([Phone Number]) Values(null) Set @ErrorNum = @@ERROR End Else -- Begin Insert into #tblExceptionTest([Phone Number]) Values(cast(@i as varchar(2)) + '12345678') End Set @i = @i +1 End -- while -- , If @ErrorNum <> 0 Begin Rollback Transaction TranExcp__2000_@@Error -- RAISERROR ('Attempt to insert null value in [Phone Number] is not allowed',16,1) End -- Else If @ErrorNum = 0 Begin Commit Transaction TranExcp__2000_@@Error End -- Select * from #tblExceptionTest
ã¹ã¯ãªããã®äžè¬çãªç®çã¯ãæåŸã®ã¬ã³ãŒãã§æå³çã«ãšã©ãŒãçºçãããããŒã«ã«å€æ°ãããã®å€ãèªã¿åãããšã§ãã ãšã©ãŒå€ããŒãã«çãããªãå ŽåããŠãŒã¶ãŒã«æå³ã®ããèŠåã衚瀺ããŸãã ãšã©ãŒããªãå Žåã¯ãçµæãä¿åããŸãã
以äžã«ç€ºãããã«ããã®ã¹ã¯ãªãããå®è¡ãããšãšã©ãŒãçºçããŸã
ã¡ãã»ãŒãž515ãã¬ãã«16ãç¶æ 2ãè¡26å 'é»è©±çªå·'ãããŒãã« 'tempdb.dboã«å€NULLãæ¿å ¥ã§ããŸãããïŒTblExceptionTest _____ 000000000023'; åã¯ãã«ãèš±å¯ããŸããã INSERTã¯å€±æããŸãã ã¹ããŒãã¡ã³ãã¯çµäºããŸããã ã¡ãã»ãŒãž50000ãã¬ãã«16ãç¶æ 1ãè¡43 [é»è©±çªå·]ã«NULLå€ãæ¿å ¥ããããšã¯èš±å¯ãããŠããŸãã
åœç¶ããã©ã³ã¶ã¯ã·ã§ã³å šäœãããŒã«ããã¯ãããããŒãã«ã«ã¯äœãå ¥åãããŸããã
@@ãšã©ãŒã䜿çšããããšã®æ¬ ç¹
- å€æ°@@ Errorã®å€ã¯ããªã¯ãšã¹ã/ã³ãã³ãã®å®è¡çŽåŸã«ç¢ºèªããå¿ èŠããããŸãã
- @@ãšã©ãŒã¯çµ¶ããå€åããŠããããããšã©ãŒã³ãŒããä¿åããã³è¡šç€ºããããã«å¥ã®å€æ°ãéå§ããå¿ èŠããããŸãã
- ãšã©ãŒã®è«ççãªæå³ã瀺ãç¹å¥ãªãšã©ãŒã¡ãã»ãŒãžãšãšãã«ããŠãŒã¶ãŒã«ãšã£ãŠé¢å¿ã®ãªãæè¡æ å ±ã衚瀺ãããŸãã
@@ Errorã®äœ¿çšã«é¢ãã詳现ãšãã¥ã¢ã³ã¹ãç¥ãããå Žåã¯ã@@ Errorã«é¢ããèšäºãåç §ããããšããå§ãããŸãã
ã°ããŒãã«å€æ°@@ TRANCOUNTã䜿çšãã
ãã®å€æ°ã¯ãå€æ°ãã¢ã¯ã»ã¹ããããšãã«å®è¡ãããŠãããã©ã³ã¶ã¯ã·ã§ã³ã®æ°ãè¿ããŸãã 説æããã@@ ERRORãšã»ãŒåãã§ããããšããã§ã«æããã§ãã ãã©ã³ã¶ã¯ã·ã§ã³ã®å®è¡äžã«çµ¶ããå€åããŸãã ãã®å ŽåããããŒã«ã«å€æ°ã䜿çšããŠãèå³æ·±ãæç¹ã§å€ãä¿åããããšã«ãªããŸãã
åBEGIN TRANSACTIONåŒã³åºãã¯@@ TRANCOUNTã1å¢å ãããåCOMMIT TRANSACTIONåŒã³åºãã¯1ãæžå°ãããŸããROLLBACKTRANSACTIONã¯@@ TRANCOUNTãå€æŽããŸããã ãšã³ããªã¯ãå€@@ TRANCOUNTã0ã«éãããšãã«ã®ã¿å ¥åããããšèŠãªãããŸãã
次ã®äŸã§@@ TRANCOUNTã®äœ¿çšãæ€èšããŠãã ããã
-- #tblExceptionTest , If OBJECT_ID('tempdb..#tblExceptionTest') Is not null Begin Drop Table #tblExceptionTest End -- Create Table #tblExceptionTest (Id int identity, [Phone Number] varchar(10) not null) -- Begin Transaction TranExcp__2000_@@TRANCOUNT -- -- @@TRANCOUNT Declare @TransactionCount int -- Declare @i int -- Set @i =1 -- While(@i <= 4) Begin -- null Phone Number If(@i = 4) Begin Insert into #tblExceptionTest([Phone Number]) Values(null) Set @TransactionCount = @@TRANCOUNT End Else -- Begin Insert into #tblExceptionTest([Phone Number]) Values(cast(@i as varchar(2)) + '12345678') End Set @i = @i +1 End -- while -- , If @TransactionCount <> 0 Begin Rollback Transaction TranExcp__2000_@@TRANCOUNT -- RAISERROR ('Attempt to insert null value in [Phone Number] is not allowed',16,1) End -- Else If @TransactionCount = 0 Begin Commit Transaction TranExcp__2000_@@TRANCOUNT End -- Select * from #tblExceptionTest
ãã®ã¹ã¯ãªããã§ã¯ãã¯ããŒãºããããã©ã³ã¶ã¯ã·ã§ã³ã®æ°ã«äŸåããŠããŸãã ãã©ã³ã¶ã¯ã·ã§ã³ã¯ãã¹ãã§ããããããã®ã¡ãœããã«ã¯ååšããæš©å©ããããŸãã
@@ TRANCOUNTã®è©³çŽ°ã«ã€ããŠã¯ã MSDN ã«ãåãåãããã ããã
ã°ããŒãã«å€æ°@@ ROWCOUNTã䜿çšãã
ãã®å€æ°ã¯ãã¯ãšãª/ã³ãã³ãã®çµæãšããŠå€æŽãããè¡ã®æ°ãè¿ããŸãã
åäœã¯åã®2ã€ãšåãã§ãããããããã«åæããããã«äžéçµæãããŒã«ã«å€æ°ã«ä¿åããŸãã
äŸïŒ
If OBJECT_ID('tempdb..#tblExceptionTest') Is not null Begin Drop Table #tblExceptionTest End Create Table #tblExceptionTest (Id int identity, [Phone Number] varchar(10) not null) Begin Transaction TranExcp__2000_@@ROWCOUNT Save Transaction TranExcp__SavePoint Declare @RowCount int Declare @i int Set @i =1 While(@i <= 4) Begin If(@i = 4) Begin Insert into #tblExceptionTest([Phone Number]) Values(null) Set @RowCount = @@ROWCOUNT End Else Begin Insert into #tblExceptionTest([Phone Number]) Values(cast(@i as varchar(2)) + '12345678') End Set @i = @i +1 End If @RowCount = 0 Begin Rollback Transaction TranExcp__SavePoint RAISERROR ('Attempt to insert null value in [Phone Number] is not allowed',16,1) End Else If @RowCount <> 0 Begin Commit Transaction TranExcp__2000_@@ROWCOUNT End Select * from #tblExceptionTest
ãã®å Žåã1ã€ã®ã¬ã³ãŒããããŒãã«ã«æ¿å ¥ããããšäºæ³ãããŸãããæ¿å ¥ãããã¬ã³ãŒãã®æ°ããŒãã®å Žåãæããã«äœããé åºã©ããã§ã¯ãããŸããã
@@ ROWCOUNTã®äœ¿çšã®è©³çŽ°ã«ã€ããŠã¯ãMSDNãåç §ããŠãã ããã
SQL Server 2005/2008ã®ãšã©ãŒåŠçïŒYukon / KatmaiïŒ
SQL Server 2005ãåžå Žã«å°å ¥ããSQL Server 2008ã§ã¢ã€ãã¢ãéçºããåŸãTSqléçºè ã¯æ°ããTry ... Catchãããã¯ã䜿çšããŸãã ãã©ã³ã¶ã¯ã·ã§ã³ã³ã³ããã¹ãã倱ãããšãªããäŸå€ããã£ããã§ããããã«ãªããŸããã
Try ... Catchãããã¯ã®äœ¿çšäŸã
If OBJECT_ID('tempdb..#tblExceptionTest') Is not null Begin Drop Table #tblExceptionTest End Begin TRY Create Table #tblExceptionTest (Id int identity, [Phone Number] varchar(10) not null) Begin Transaction TranExcpHandlingTest_2005_2008 Declare @i int Set @i =1 While(@i <= 4) Begin If(@i = 4) Begin Insert into #tblExceptionTest([Phone Number]) Values(null) End Else Begin Insert into #tblExceptionTest([Phone Number]) Values(cast(@i as varchar(2)) + '12345678') End Set @i = @i +1 End Commit Transaction TranExcpHandlingTest_2005_2008 End Try Begin Catch Begin Rollback Transaction TranExcpHandlingTest_2005_2008 RAISERROR ('Attempt to insert null value in [Phone Number] is not allowed',16,1) End End Catch Select * From #tblExceptionTest
ãã®äŸã§ã¯ãéæ¥çãªæ瀺ã«ãã£ãŠã¹ã¯ãªããå®è¡ãšã©ãŒãå€å¥ããããã«ãè£å©å€æ°ã¯äœ¿çšãããªããªããŸããã
ã¹ã¯ãªãããå®è¡ãããšã次ã®ãããªã¡ãã»ãŒãžã衚瀺ãããŸãã
ã¡ãã»ãŒãž50,000ãã¬ãã«16ãç¶æ 1ãè¡45 [é»è©±çªå·]ã«nullå€ãæ¿å ¥ããããšã¯èš±å¯ãããŠããŸãã
ãããããã§ã«æ°ã¥ããããã«ãä»åã¯ãšã©ãŒã¡ãã»ãŒãžã«èšå®ããããã®ã ãã衚瀺ãããŸããã SQL Serverã¯ãè¿œå ã®ãŠãŒã¶ãŒãå°ãããã¡ãã»ãŒãžã衚瀺ããŠããŸããã å®è¡å¯èœã³ãŒãã¯tryãããã¯ã«çµã¿èŸŒãŸãããšã©ãŒåŠçã¯catchãããã¯ã«çµã¿èŸŒãŸããŸãã çµæã¯ãã¯ãªãŒã³ã§æ確ãªã³ãŒãã§ãã ç®çã®ã³ãŒãããã¹ãŠãšã©ãŒãªãã§æž¡ãããå ŽåãCatchãããã¯ããã®ã³ãŒãã¯åŒã³åºãããŸããã
æãéèŠãªããšã¯ãCatchãããã¯ã¯ããšã©ãŒã®åå ã詳现ã«åæããé©åãªã¬ãã«ã§ãŠãŒã¶ãŒã«éç¥ããæ©èœã®ã»ãããæäŸããŸãã äŸå€ã解æããããã®é¢æ°ïŒ
- ERROR_NUMBER
- ERROR_SEVERITY
- ERROR_STATE
- ERROR_LINE
- ERROR_PROCEDURE
- ERROR_MESSAGE
ãããã®é¢æ°ã䜿çšããŠãåã«èª¬æããCatchã¹ã¯ãªãããããã¯ã®æžãæããè©Šã¿ãŸãã
Begin Catch -- Begin -- Rollback Transaction TranExcpHandlingTest_2005_2008 SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_SEVERITY() AS ErrorSeverity, ERROR_STATE() AS ErrorState, ERROR_PROCEDURE() AS ErrorProcedure, ERROR_LINE() AS ErrorLine, ERROR_MESSAGE() AS ErrorMessage; End End Catch
ãµãŒããŒãããã®å¿çãååŸããŸãã
RaiseErroré¢æ°ã䜿çšããå Žåã®æ¬ ç¹
1ãã®é¢æ°ãCatchãããã¯ã§ç€ºãããã®ãæãåºããšãåé¡ã®åå ãšããŠè¡çªå·45ãåç §ããŠããããšãããããŸãã
ãã ããå®éã«ã¯ãè¡çªå·24ã§ãšã©ãŒãçºçããããã
#tblExceptionTestïŒ[é»è©±çªå·]ïŒå€ã«æ¿å ¥ïŒnullïŒ
ERROR_LINEïŒïŒé¢æ°ã¯åžžã«ãšã©ãŒãçºçããå®éã®å Žæãè¿ããŸãã æ°ããé¢æ°ã®åäœã瀺ãå¥ã®æ¹æ³ã¯æ¬¡ã®ãšããã§ãã
Begin Catch Begin Rollback Transaction TranExcpHandlingTest_2005_2008 DECLARE @errNumber INT = ERROR_NUMBER() DECLARE @errMessage VARCHAR(500) = 'Attempt to insert null value in [Phone Number] is not allowed' RAISERROR('Error Number: %d, Message: %s', 16, 1, @errNumber, @errMessage) End End Catch
ãã®å ŽåãSQL Serverãšã³ãžã³ã¯æ¬¡ã®ã¡ãã»ãŒãžã衚瀺ããŸãã
ãã®ããšãããRaiseErrorã䜿çšãããšãäŸå€ãçºçããã¹ã¯ãªããå ã®å®éã®å Žæã瀺ãããšãã§ããªããªããšçµè«ä»ããããšãã§ããŸãã
2 RaiseErroré¢æ°ã®æ¬¡ã®æ¬ ç¹ã¯ãåãäŸå€ãå床åŒã³åºããŠåŒã³åºãéå±€ãæž¡ãããšãã§ããªãããšã§ãã ãããã£ãŠãcatchãããã¯ã次ã®ããã«æžãæãããš
Begin Catch Begin Rollback Transaction TranExcpHandlingTest_2005_2008 RAISERROR(515, 16, 1) End End Catch
åä¿¡ãããšã©ãŒã¡ãã»ãŒãžã¯æ¬¡ã®ããã«ãªããŸãã
ã¡ãã»ãŒãž2732ãã¬ãã«16ãç¶æ 1ãè¡46ãšã©ãŒçªå·515ã¯ç¡å¹ã§ãã çªå·ã¯13000ã2147483647ã§ãªããã°ãªããã50,000ã«ããããšã¯ã§ããŸãã
ãã®çç±ã®1ã€ã¯ãæ°ãããšã©ãŒã¡ãã»ãŒãžãéå§ããããã«ã sysããŒãã«ã«ãšã©ãŒçªå·ãå«ãŸããŠããå¿ èŠãããããšã§ãã ã¡ãã»ãŒãž
RaiseErroré¢æ°ã®ãã詳现ãªèª¿æ»ã«ã€ããŠã¯ã以äžãèªãããšããå§ãããŸãã
SQL Server 2011ïŒDenaliïŒã®ãšã©ãŒåŠç
RaiseErroré¢æ°ã®äžèšã®æ¬ ç¹ã¯ã æ°ãã Throw ã³ãã³ãã§æ£åžžã«å æã§ããŸãã
åã«ææããRaiseErroré¢æ°ã®æåã®æ¬ ç¹ã¯ããšã©ãŒçºçã®æ£ç¢ºãªè¡ãåç §ã§ããªãããšã§ãã ãšã©ãŒãçºçããå Žæããã©ããããé¢ããŠããããèããŠãThrowã³ãã³ãã䜿çšããŠããŸãã
Throwã³ãã³ãã䜿çšããŠãCatchãããã¯ãæžãæããŸãã
Begin Catch Begin Rollback Transaction TranExcpHandlingTest_2011; THROW End End Catch
åºåã¯æ¬¡ã®ããã«ãªããŸãã
ããã¯ãŸãã«ãšã©ãŒãçºçããå Žæã§ãã ãŸããããã¯ä»ã®ãšããããŸãåäœããŸãã
2çªç®ã®æ¬ ç¹ã¯ãRAISE ERRORãsys.messagesããŒãã«ã«æ ŒçŽãããŠãããšã©ãŒçªå·ãäºæããŠãããããRaiseErroré¢æ°ãäŸå€ãåçºçã§ããªãããšã§ãã Throwã³ãã³ãã¯ããšã©ãŒçªå·ãsys.messagesã·ã¹ãã ããŒãã«ã®ç¯å²ã«ããããšãæ³å®ããŠããŸãããã50,000ãã2147483647ãŸã§ã®ç¯å²ã«èšå®ã§ããŸãã
ç¹°ãè¿ããŸãããæ°ããç¥èã«åŸã£ãŠCatchãããã¯ãå€æŽããŸãã
Begin Catch Begin Rollback Transaction TranExcpHandlingTest_2011; THROW 50001,'Attempt to insert null value in [Phone Number] is not allowed',1 End End Catch
äŸå€ã®çµæã¯
ã¡ãã»ãŒãž50001ãã¬ãã«16ãç¶æ 1ãè¡45 [é»è©±çªå·]ã«nullå€ãæ¿å ¥ããããšã¯èš±å¯ãããŠããŸãã
çŸåšãSQL Serverã¯ãšã©ãŒããã£ããããå€ãã®æ¹æ³ãæäŸããŠããŸããããããŸã§ã®ãšãããTry ... Catchãããã¯ã䜿çšããŠãã¹ãŠã®ãšã©ãŒããã£ããã§ããããã§ã¯ãããŸããã äŸïŒ
- æ§æãšã©ãŒã¯ãSSMSã®ã¯ãšãªãšãã£ã¿ãŒã«ãã£ãŠãã£ãããããŸãã
- ééã£ããªããžã§ã¯ãå
次ã®ã¹ã¯ãªãããå®è¡ã®ããã«éä¿¡ããããšããå ŽåïŒ
Begin Try -- tblInvalid Insert Into tblInvalid(Id,DOB) Values(1,DATEADD(year,1,'2011-02-26')) End Try Begin Catch -- THROW End Catch
次ã®èšç»ã®ãšã©ãŒã¡ãã»ãŒãžã衚瀺ãããŸãã
ã¡ãã»ãŒãž208ãã¬ãã«16ãç¶æ 0ãè¡3ç¡å¹ãªãªããžã§ã¯ãå 'tblInvalid'ã
ãããã®ã¿ã€ãã®ãšã©ãŒãååããããšã¯ã»ãšãã©äžå¯èœã§ããããšãããããŸãã
ãããã ãã€ãã®ããã«ãããªããæããã®ãå®çŸããããã®å°ããªããªãã¯ããããŸãã äž»ãªã¢ã€ãã¢ã¯ã2ã€ã®ã¹ãã¢ãããã·ãŒãžã£ãäœæããTry ... Catchãããã¯ã§ä»ã®1ã€ãåŒã³åºããäŸå€ããã£ããããããšã§ãã ä»®å®ã蚌æããããã«ã次ã®ã¹ã¯ãªãããå®éšã«äœ¿çšããŸãã
-- , , If Exists (Select * from sys.objects where name = 'usp_InternalStoredProc' and type = 'P') Drop Procedure usp_InternalStoredProc Go -- Create Procedure usp_InternalStoredProc As Begin Begin Transaction TranExcpHandlingTest_2011 Begin Try -- Insert Into tblInvalid(Id,DOB) Values(1,DATEADD(year,1,'2011-02-26')) -- Commit Transaction TranExcpHandlingTest_2011 End Try Begin Catch If @@TRANCOUNT > 0 Rollback Transaction TranExcpHandlingTest_2011 Print 'In catch block of internal stored procedure.... throwing the exception'; -- THROW End Catch End Go -- -- , , If Exists (Select * from sys.objects where name = 'usp_ExternalStoredProc' and type = 'P') Drop Procedure usp_ExternalStoredProc Go -- Create Procedure usp_ExternalStoredProc As Begin Begin Try -- Exec usp_InternalStoredProc End Try Begin Catch Print 'In catch block of external stored procedure.... throwing the exception'; SELECT ERROR_NUMBER() AS ErrorNumber ,ERROR_SEVERITY() AS ErrorSeverity ,ERROR_STATE() AS ErrorState ,ERROR_PROCEDURE() AS ErrorProcedure ,ERROR_LINE() AS ErrorLine ,ERROR_MESSAGE() AS ErrorMessage; THROW End Catch End Go -- Exec usp_ExternalStoredProc
ExternalStoredProcããã·ãŒãžã£ãéå§ãããšã次ã®ã¡ãã»ãŒãžã衚瀺ãããŸãã
In catch block of external stored procedure.... throwing the exception (1 row(s) affected) Msg 208, Level 16, State 1, Procedure usp_InternalStoredProc, Line 8 Invalid object name 'tblInvalid'.
çµæããã«ã«ã¯æ¬¡ã®ããŒã¿ã衚瀺ãããŸãã
å¿ èŠãªãã®ïŒ
ããã§ãã³ãŒãã®ä»çµã¿ã«ã€ããŠå°ã説æããŸãã usp_InternalStoredProcãšusp_ExternalStoredProcã® 2ã€ã®ã¹ãã¢ãããã·ãŒãžã£ããããŸã ã usp_InternalStoredProcã§ã¯ãååšããªãããŒãã«#tblInnerTempTableã«ã¬ã³ãŒããæ¿å ¥ããããšããŸããããã®çµæãäŸå€ãçºçããŸãããã®äŸå€ã¯ãå€éšããã·ãŒãžã£ã«ããå€éšCatchãããã¯ã«ãã£ãŠãã£ãããããŸãã
ããã«ããšã©ãŒã®è¡ãšããã¹ãã¯ç§ãã¡ã®æåŸ ã«å®å šã«æºæ ããŠãããæ£ç¢ºãªå Žæã瀺ããŠããŸãã
å€éšããã·ãŒãžã£ã®ä»åŸã®THROWåŒãã»ãã³ãã³ã§éããããšãå¿ããªãããšãéåžžã«éèŠã§ãã THROWã¯æ°ããã³ãã³ãã®ã»ããã§ãªããã°ãªããŸããã ããã§ãªãå Žåããšã©ãŒãçºçããŸã
ãTHROWãä»è¿ã®æ§æãæ£ãããããŸããã
THROWã®è©³çŽ°ã«ã€ããŠã¯ãMSDNãåç §ããŠãã ããã
ãµã€ã¯ã«ããã®è»¢éïŒ
MS SQL Server 2011ïŒ ã¹ã¿ã³ãã¢ãã³ããŒã¿ããŒã¹ ã æ°ããã·ãŒã±ã³ã¹ãªããžã§ã¯ã ã ãªãã»ããã¹ããŒãã¡ã³ã ã ãšã©ãŒåŠç ã çµæã»ããæ§æ ã SSMSã®æ°æ©èœ ã