Skip to main content
add spaces around =
Source Link
rolfl
  • 98.1k
  • 17
  • 220
  • 419

In terms of the raw/basic functionality, what you have is fine. The transactional logic is good.

Readability is the only concern I have, and would rewrite your code as (note, there are some spaces I added around some = conditions):

BEGIN TRANSACTION UPDATE SalaryTrans SET carried_forward_amount = @carriedForwardAmount, net_wage=@netWagenet_wage = @netWage, processed_date = @processedDate WHERE employee_id=@employeeIDemployee_id = @employeeID AND reference = @reference DELETE FROM CarriedForward WHERE employee_id = @employeeID INSERT INTO CarriedForward (employee_id, carried_forward_amount) VALUES(@employeeID, @carriedForwardAmount) COMMIT; 

I assume the business logic is correct. It is unusual to have a table in a database where deletes happen. I am more accustomed to having some sort of history for the data, and the delete is a logical thing, not a real delete. This is normally for audit/reporting purposes.

In terms of the raw/basic functionality, what you have is fine. The transactional logic is good.

Readability is the only concern I have, and would rewrite your code as:

BEGIN TRANSACTION UPDATE SalaryTrans SET carried_forward_amount = @carriedForwardAmount, net_wage=@netWage, processed_date = @processedDate WHERE employee_id=@employeeID AND reference = @reference DELETE FROM CarriedForward WHERE employee_id = @employeeID INSERT INTO CarriedForward (employee_id, carried_forward_amount) VALUES(@employeeID, @carriedForwardAmount) COMMIT; 

I assume the business logic is correct. It is unusual to have a table in a database where deletes happen. I am more accustomed to having some sort of history for the data, and the delete is a logical thing, not a real delete. This is normally for audit/reporting purposes.

In terms of the raw/basic functionality, what you have is fine. The transactional logic is good.

Readability is the only concern I have, and would rewrite your code as (note, there are some spaces I added around some = conditions):

BEGIN TRANSACTION UPDATE SalaryTrans SET carried_forward_amount = @carriedForwardAmount, net_wage = @netWage, processed_date = @processedDate WHERE employee_id = @employeeID AND reference = @reference DELETE FROM CarriedForward WHERE employee_id = @employeeID INSERT INTO CarriedForward (employee_id, carried_forward_amount) VALUES(@employeeID, @carriedForwardAmount) COMMIT; 

I assume the business logic is correct. It is unusual to have a table in a database where deletes happen. I am more accustomed to having some sort of history for the data, and the delete is a logical thing, not a real delete. This is normally for audit/reporting purposes.

Source Link
rolfl
  • 98.1k
  • 17
  • 220
  • 419

In terms of the raw/basic functionality, what you have is fine. The transactional logic is good.

Readability is the only concern I have, and would rewrite your code as:

BEGIN TRANSACTION UPDATE SalaryTrans SET carried_forward_amount = @carriedForwardAmount, net_wage=@netWage, processed_date = @processedDate WHERE employee_id=@employeeID AND reference = @reference DELETE FROM CarriedForward WHERE employee_id = @employeeID INSERT INTO CarriedForward (employee_id, carried_forward_amount) VALUES(@employeeID, @carriedForwardAmount) COMMIT; 

I assume the business logic is correct. It is unusual to have a table in a database where deletes happen. I am more accustomed to having some sort of history for the data, and the delete is a logical thing, not a real delete. This is normally for audit/reporting purposes.