Untitled
unknown
plain_text
2 years ago
883 B
3
Indexable
BEGIN TRANSACTION; DECLARE @ErrorThreshold INT = 5; -- Change the value to set the error threshold BEGIN TRY -- Insert movies from @ImportFileContent into the #Movies table INSERT INTO #Movies (MovieName, ReleaseDate, Genre, Director) SELECT MovieName, ReleaseDate, Genre, Director FROM @ImportFileContent; -- Check for errors during the insertion IF @@ROWCOUNT < (SELECT COUNT(*) FROM @ImportFileContent) - @ErrorThreshold BEGIN RAISERROR('Too many errors occurred during insertion. Rolling back.', 16, 1); END ELSE BEGIN -- If no error threshold is reached, commit the transaction COMMIT TRANSACTION; PRINT 'Movies inserted successfully!'; END END TRY BEGIN CATCH -- Handle the error and rollback the transaction ROLLBACK TRANSACTION; PRINT 'Error occurred: ' + ERROR_MESSAGE(); END CATCH;
Editor is loading...