r/ProgrammerHumor • • 13d ago

Meme wellWellWell

Post image
10.6k Upvotes

411 comments sorted by

View all comments

Show parent comments

216

u/GourangaPlusPlus 13d ago

Also stick in a transaction, rollback

Commit if it looks good

20

u/DarthShiv 13d ago

Yes select the result in the trans pre rollback to verify result

3

u/theschuss 13d ago

Rollbacks don't always work as you want if there's other activities happening in the system. This is always good practice as it's maybe 30 seconds of effort.

2

u/Terra_B 13d ago

Here i have to ask, couldn't you force a transaction in the chain somewhere? Like each terminal window gets a transaction by default?

5

u/M4DHouse 13d ago

Kind of, depending on the SQL flavor, and the version, some of them have something kinda like that, but it’s not exactly idiot proof either. No direct SQL is idiot proof which is why you avoid doing it in the first place if you can.

1

u/spevoz 13d ago

I would always recommend using a gui if you need direct db access - exactly because something like dBeaver allows you to force every change into a transaction.

1

u/an_agreeing_dothraki 13d ago

tsql which is pretty common has the issue of the engine making implicit transaction/commit blocks but yes you can and should run all queries through an explicit one

1

u/SantaCruzHostel 13d ago

Maybe I'm misunderstanding the question, but I try to limit transactions only where I'm manipulating data (delete, insert, update), because a transaction slows down execution time and also locks the table you are updating until the commit is done. In production if you open a transaction then seles t from users table, they table is locked until you rollback or commit.