Skip to content

Instantly share code, notes, and snippets.

View ronascentes's full-sized avatar

Rodrigo Nascentes ronascentes

View GitHub Profile
@ronascentes
ronascentes / process_large_amount_records.sql
Last active February 17, 2022 19:48
Delete/ Update a large amount of records
-- got from https://sqlperformance.com/2013/03/io-subsystem/chunk-deletes
DECLARE @rows INT, @ErrorMessage NVARCHAR(4000);
SET NOCOUNT, XACT_ABORT ON;
SET @rows = 1;
BEGIN TRY
WHILE (@rows > 0)
BEGIN
BEGIN TRANSACTION;
@ronascentes
ronascentes / try_catch_sample.sql
Created October 1, 2016 17:40
Using TRY...CATCH in T-SQL
SET XACT_ABORT ON;
BEGIN TRY
BEGIN TRANSACTION;
-- A FOREIGN KEY constraint exists on this table. This
-- statement will generate a constraint violation error.
DELETE FROM Production.Product
WHERE ProductID = 980;
-- If the DELETE statement succeeds, commit the transaction.