Questi sono i 2 quadri Posso consigliare
T.S.T.
http://tst.codeplex.com/
Testing codice SQL Server con TST
http://www.infoq.com/articles/tst-sql-server
tSQLt
http://tsqlt.org/
test SQL (corridore per tSQLt)
http://www.red-gate.com/products/sql-development/sql-test/
Update 1
Leggendo la tua risposta forse si trova la seguente discarica utile.
TRY CATCH è stato introdotto con SQL Server 2005 (e per questo motivo non si dovrebbe mai guardare a qualcosa di più vecchio del 2005). È possibile (ri) generare un'eccezione utilizzando una stored procedure menzionata nel mio dump, incluso il numero di riga. In SQL Server 2012 (finalmente!) Hanno introdotto il lancio mentre si menziona la creazione di Tsql in un linguaggio solido dopo 14 anni.
Quindi, ecco la mia discarica, ho bisogno di ripulirlo un giorno così è più copia incolla amichevole.
SET XACT_ABORT ON
SET CONCAT_NULL_YIELDS_NULL OFF
DECLARE @message varchar (max)
DECLARE @who varchar (255)
set @who = OBJECT_NAME(@@PROCID) -- name of the currently executing sproc
BEGIN TRY
-- ======================================================================================
SET @message = 'HELLO'
EXEC Log @who, @message
....
-- ======================================================================================
SET @message = 'GOODBYE'
EXEC Log @who, @message
END TRY
BEGIN CATCH
-- ======================================================================================
--If an error generated in a TRY block causes the state of the current transaction to be invalidated, the transaction is classified as an uncommittable transaction.
--An error that ordinarily ends a transaction outside a TRY block causes a transaction to enter an uncommittable state when the error occurs inside a TRY block.
-- http://msdn.microsoft.com/en-us/library/ms175976.aspx
if XACT_STATE() = -1 rollback;
-- ======================================================================================
SET @message = 'Rolling Back transaction if present'
EXEC Log @who, @message
-- Its important to rollback the transaction at the very start of the catch.
-- Otherwise the records that are written to the log will also be roll backed.
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRAN
END
-- ======================================================================================
SET @message = 'Error Occured '
set @message = @message + ' ERROR_NUMBER() : ' + cast(ERROR_NUMBER() as varchar(max))
set @message = @message + ' ERROR_SEVERITY() : ' + cast(ERROR_SEVERITY() as varchar(max))
set @message = @message + ' ERROR_STATE() : ' + cast(ERROR_STATE() as varchar(max))
set @message = @message + ' ERROR_PROCEDURE() : ' +cast(ERROR_PROCEDURE() as varchar(max))
set @message = @message + ' ERROR_LINE() : ' + cast(ERROR_LINE() as varchar(max))
set @message = @message + ' ERROR_MESSAGE() : ' + cast(ERROR_MESSAGE() as varchar(max))
EXEC Log @who, @message
exec usp_RethrowError
END CATCH
Error logging sproc and table
CREATE PROCEDURE [dbo].[Log]
(
@who varchar(255),
@message varchar(max)
)
AS
SET XACT_ABORT ON
SET CONCAT_NULL_YIELDS_NULL OFF
INSERT INTO [ApplicationLog]
(
[Date],
[Level],
[Logger],
[Host],
[Message]
)
VALUES
(
getDate(),
'INFO',
@who,
'dummy',
@message
)
CREATE TABLE [dbo].[ApplicationLog] (
[Id] [int] IDENTITY(1, 1) NOT NULL,
[Date] [datetime] NOT NULL,
[Thread] [varchar](255) NULL,
[Level] [varchar](50) NOT NULL,
[Logger] [varchar](255) NOT NULL,
[Host] [varchar](50) NOT NULL,
[Message] [varchar](max) NOT NULL,
[Exception] [varchar](max) NULL
)
Rethrow an exception
ALTER PROCEDURE [dbo].[usp_RethrowError]
-- BOL contains a good example of that, there is a stored procedure called usp_RethrowError
AS -- Return if there is no error information to retrieve.
SET XACT_ABORT ON
SET CONCAT_NULL_YIELDS_NULL OFF
IF ERROR_NUMBER() IS NULL
RETURN ;
DECLARE @ErrorMessage NVARCHAR(4000),
@ErrorNumber INT,
@ErrorSeverity INT,
@ErrorState INT,
@ErrorLine INT,
@ErrorProcedure NVARCHAR(200) ;
-- Assign variables to error-handling functions that
-- capture information for RAISERROR.
SELECT @ErrorNumber = ERROR_NUMBER(), @ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE(), @ErrorLine = ERROR_LINE(),
@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-') ;
-- Building the message string that will contain original
-- error information.
SELECT @ErrorMessage = N'Error %d, Level %d, State %d, Procedure %s, Line %d, ' +
'Message: ' + ERROR_MESSAGE() ;
-- Raise an error: msg_str parameter of RAISERROR will contain
-- the original error information.
RAISERROR (@ErrorMessage, @ErrorSeverity, 1, @ErrorNumber, -- parameter: original error number.
@ErrorSeverity, -- parameter: original error severity.
@ErrorState, -- parameter: original error state.
@ErrorProcedure, -- parameter: original error procedure name.
@ErrorLine-- parameter: original error line number.
) ;
Aggiornamento: mi sono appena imbattuto in questa utile scrittura: ["Introduzione a Test Driven Design in SQL Server"] (http://www.sqlmag.com/print/sql-server/test-driven-design-sql -server-142881) – kmote