Nortwind veritabanını kullanarak basit bir işlem yaparak örnek kullanımı inceleyebiliriz.
BEGIN TRY
set XACT_ABORT on
BEGIN TRAN Deneme
DECLARE @productName varchar(100)
DECLARE @categoryId int
declare writerLoop cursor for
Select top 3 ProductName , CategoryID From [Northwind].[dbo].[Products]
open writerLoop
fetch next from writerLoop into @productName,@categoryId
while @@FETCH_STATUS =0
begin
select 'Ürün Adı : ' + @productName ÜrünAdı,
(select 'Kategori Adı : '+ CategoryName from Categories where CategoryID=@categoryId) KatergoriAdı
fetch next from writerLoop into @productName,@categoryId
end
close writerLoop
Deallocate writerLoop
COMMIT TRAN Deneme
END TRY
-- hata varsa kayıtları geri al
BEGIN CATCH
ROLLBACK TRAN Deneme
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() as ErrorState,
ERROR_PROCEDURE() as ErrorProcedure,
ERROR_LINE() as ErrorLine,
ERROR_MESSAGE() as ErrorMessage;
END CATCH
Hiç yorum yok:
Yorum Gönder