Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/03/2013, 09:45
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 9 meses
Puntos: 774
Respuesta: Prevenir error en procedimiento

puedes manejarlo con try y catch para cada una de tus inserciones, ya si falla una continua con la siguiente algo asi:



Código SQL:
Ver original
  1. BEGIN TRANSACTION;
  2.  
  3. BEGIN TRY
  4.     -- Generate a constraint violation error.
  5.     DELETE FROM Production.Product
  6.     WHERE ProductID = 980;
  7. END TRY
  8. BEGIN CATCH
  9.     SELECT
  10.         ERROR_NUMBER() AS ErrorNumber
  11.         ,ERROR_SEVERITY() AS ErrorSeverity
  12.         ,ERROR_STATE() AS ErrorState
  13.         ,ERROR_PROCEDURE() AS ErrorProcedure
  14.         ,ERROR_LINE() AS ErrorLine
  15.         ,ERROR_MESSAGE() AS ErrorMessage;
  16.  
  17.     IF @@TRANCOUNT > 0
  18.         ROLLBACK TRANSACTION;
  19. END CATCH;
  20.  
  21. IF @@TRANCOUNT > 0
  22.     COMMIT TRANSACTION;
  23. GO
  24. BEGIN TRANSACTION2;
  25.  
  26. BEGIN TRY
  27.     -- Generate a constraint violation error.
  28.     DELETE FROM Production.Product
  29.     WHERE ProductID = 980;
  30. END TRY
  31. BEGIN CATCH
  32.     SELECT
  33.         ERROR_NUMBER() AS ErrorNumber
  34.         ,ERROR_SEVERITY() AS ErrorSeverity
  35.         ,ERROR_STATE() AS ErrorState
  36.         ,ERROR_PROCEDURE() AS ErrorProcedure
  37.         ,ERROR_LINE() AS ErrorLine
  38.         ,ERROR_MESSAGE() AS ErrorMessage;
  39.  
  40.     IF @@TRANCOUNT > 0
  41.         ROLLBACK TRANSACTION2;
  42. END CATCH;
  43.  
  44. IF @@TRANCOUNT > 0
  45.     COMMIT TRANSACTION2;
  46. GO
y asi sucesivamente para cada una de tus transacciones :)

saludos,
Libras
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me