A trick to make the safe direct change in the Database

A trick to make the safe direct change in the Database

Today I want to share the way you can safely make changes in the database.

Although this approach is highly not recommended you can encounter a situation in which this is the only possible approach to correct the data.

If you're dealing with a scenario where numerous entries may need correction, and you want to ensure that the update is applied correctly, it is indeed prudent to wrap the SQL script in a transaction. By doing so, you can review the updates before committing them. Here's an example script that includes transaction control with the option to roll back:

BEGIN TRANSACTION;

-- Update statement

UPDATE [YOUR.FIELD in DB]

SET [YOUR.VALUE] = n

FROM ... (here goes the extract from DB)

-- Select statement to verify the updates

SELECT * FROM .....

-- If the verification is successful and you're satisfied with the updates, commit the transaction

-- COMMIT;

-- If the updates are not as intended, roll back the transaction to undo the changes

-- ROLLBACK;

Sorry for not giving the detailed example.

I wanted just to give a clue for those who may someday tackle a problem.

If you have any questions, do not hesitate to write in the Comments or in DMs.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了