Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Additional check in Delete Transaction

$
0
0

I'd like to add 2 if statements to the this delete transaction and check the @rowcount value before the COMMIT, is this the correct way to do it:

DECLARE @APP_ID uniqueidentifier
SET @APP_ID = '1234'

BEGIN TRY
	BEGIN TRANSACTION;
	
	--There could be more than 1 record deleted from this Table
	DELETE 
	FROM dbo.SERVERS_APPS 
	WHERE SA_APP_ID = @APP_ID
	
	IF @@ROWCOUNT >= 1
		--There should only be than 1 record deleted from this Table
		DELETE 
		FROM dbo.ENVIRONMENTS_APPS
		WHERE ENVA_APP_ID = @APP_ID
		IF @@ROWCOUNT = 1
		COMMIT TRANSACTION; 
END TRY
BEGIN CATCH
	ROLLBACK TRANSACTION
END CATCH


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>