elimesika
asked on
Simple SQL Question
HI Experts
Please look at the attached code, it is an auto-generated code by MS Enterprise Library, Can you explain what is the purpose of the check for @@rowcount value and why if it is 0 , we have any concurrency problem. For me , it seems that the TRY/CATCH is enough to handle all errors and if the update have no rows to work on , @@rowcount will be 0 and it is completely OK.
Am I missing something? or I can safely remove this check and stay only with the TRY/CATCH ???
Thanks
Please look at the attached code, it is an auto-generated code by MS Enterprise Library, Can you explain what is the purpose of the check for @@rowcount value and why if it is 0 , we have any concurrency problem. For me , it seems that the TRY/CATCH is enough to handle all errors and if the update have no rows to work on , @@rowcount will be 0 and it is completely OK.
Am I missing something? or I can safely remove this check and stay only with the TRY/CATCH ???
Thanks
ALTER PROCEDURE [dbo].[UpdateVmStatistics]
@cpu_sys decimal(18,0) = NULL,
@cpu_user decimal(18,0) = NULL,
@elapsed_time decimal(18,0) = NULL,
@rx_dropped_1 decimal(18,0) = NULL,
@rx_dropped_2 decimal(18,0) = NULL,
@rx_rate_1 decimal(18,0) = NULL,
@rx_rate_2 decimal(18,0) = NULL,
@tx_dropped_1 decimal(18,0) = NULL,
@tx_dropped_2 decimal(18,0) = NULL,
@tx_rate_1 decimal(18,0) = NULL,
@tx_rate_2 decimal(18,0) = NULL,
@usage_cpu_percent int = NULL,
@usage_mem_percent int = NULL,
@usage_network_percent int = NULL,
@vm_guid uniqueidentifier,
@vm_if_id_1 int = NULL,
@vm_if_id_2 int = NULL,
@vm_if_name_1 nvarchar(40) = NULL,
@vm_if_name_2 nvarchar(40) = NULL,
@vm_line_rate_1 int = NULL,
@vm_line_rate_2 int = NULL
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
UPDATE [dbo].[vm_statistics]
SET [cpu_sys] = @cpu_sys, [cpu_user] = @cpu_user, [elapsed_time] = @elapsed_time, [rx_dropped_1] = @rx_dropped_1, [rx_dropped_2] = @rx_dropped_2, [rx_rate_1] = @rx_rate_1, [rx_rate_2] = @rx_rate_2, [tx_dropped_1] = @tx_dropped_1, [tx_dropped_2] = @tx_dropped_2, [tx_rate_1] = @tx_rate_1, [tx_rate_2] = @tx_rate_2, [usage_cpu_percent] = @usage_cpu_percent, [usage_mem_percent] = @usage_mem_percent, [usage_network_percent] = @usage_network_percent, [vm_if_id_1] = @vm_if_id_1, [vm_if_id_2] = @vm_if_id_2, [vm_if_name_1] = @vm_if_name_1, [vm_if_name_2] = @vm_if_name_2, [vm_line_rate_1] = @vm_line_rate_1, [vm_line_rate_2] = @vm_line_rate_2
WHERE [vm_guid]=@vm_guid
/* Can you explain this ??? */
IF @@ROWCOUNT = 0
BEGIN
RAISERROR('Concurrent update error. Updated aborted.', 16, 2)
END
END TRY
BEGIN CATCH
EXEC RethrowError;
END CATCH
SET NOCOUNT OFF
END
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER