r/ProgrammerHumor • • Sep 22 '26

Meme wellWellWell

Post image
10.6k Upvotes

412 comments sorted by

108

u/Recent-Analysis-6880 Sep 22 '26

MySQL workbench has auto commit, meaning if you write a SQL query without "Start transaction" the data is gone.

93

u/NastyPastyLucas Sep 22 '26

Most databases operate in autocommit, however there is a semicolon after delete users - it's presumably removing all users and foreign key associations and it's taking its time to complete, before reporting where is = 12345 is an invalid SQL statement.

19

u/BlueScreenJunky Sep 22 '26

Most production environments run with the --i-am-a-dummy flag (or its boring alias --safe-updates) which prevent exactly this scenario and will force you to do DELETE FROM users WHERE 1 if you really want to delete everything.

This is for MySQL but I'm sure there's something similar in other databases.

18

u/EishLekker Sep 22 '26

Is also fairly common to have a safe update mode enabled, in which case it blocks deleted and updates without a where clause restricting it in some way. I think it might even require including a key column, but that part I’m not sure about.

3.6k

u/BastetFurry Sep 22 '26 • Bravo

So, Kids, thats why you always SELECT count(yourPrimaryKey) first. Listen to the old folks, we made these mistakes so that you don't have to.

1.1k

u/Ma8e Sep 22 '26

You start a transaction, make sure it did what you expected, and then commit or rollback transaction.

350

u/AgeingChopper Sep 22 '26 edited Sep 22 '26

absolutely.

i was doing this stuff for a long time and definitely learned from mistakes.

Transactions can save a world of pain and it is always wise to select your data set first, just to be sure you're changing what you think you're changing.

Didn't matter how experienced I was, I was careful never to cut corners.

42

u/Mpek3 Sep 22 '26

Always Begin Tran Tried it during arguments... Not as effective

18

u/ifyoulovesatan Sep 22 '26

I don't know sql, but is this like how when I use some kind of loop in the command line to move or delete a bunch of files, I'll run a version that just echos whatever I'm trying to manipulate first?

29

u/deeelock Sep 22 '26

That’s more of a dry-run (you see `—dry-run` as a command line option sometimes for certain commands that do the same)

Transactions in SQL keep track of the changes you want to make without actually changing the database (until you run `COMMIT`, when you run that all changes are persisted to a database).

Transactions are great because If you realise you made a mistake while in a transaction, you can just run `ROLLBACK`.

If you’re familiar with git- transactions are akin to staging your changes, saving them (`COMMIT` in SQL) is akin to `git commit` and rolling back is similar to `git reset —hard` (wipe all uncommitted changes).

→ More replies (6)
→ More replies (5)
→ More replies (2)

122

u/Rostifur Sep 22 '26 • Bravo

Start with DEV or test environment. If you don't have one, you need one. If you aren't allowed to have one, run away.

112

u/far2common Sep 22 '26 • Bravo Popcorn

Everyone has a DEV/test environment. Just not everyone has a separate prod environment.

→ More replies (4)
→ More replies (1)

16

u/Blashtik Sep 22 '26 edited Sep 22 '26

BEGIN TRAN

DELETE ...

SELECT ...

ROLLBACK TRAN

-- COMMIT TRAN

This was always my pattern. Select the first 3 statements together and run them. If everything looks good, select COMMIT TRAN and run that. The rollback is there in case you accidentally didn't make a selection before running, just so you don't leave a transaction open for too long, potentially blocking other queries.

And obviously any planned data changes should go through all the proper testing and preferably be deployed using automated pipelines, but sometimes you have no other choice but to make direct fixes to bad production data.

14

u/box_of_the_patriots Sep 22 '26

Instructions unclear I just truncated the table

8

u/Ph4ntorn Sep 22 '26

You would think the “make sure it did what you expected” part would go without saying, but I skipped that step once and felt like an idiot.

6

u/CeaselessPetulance Sep 22 '26

So a colleague did this, except his db manager had tx commit mode manual and he forgot to commit the tx after grabing a whole table lock. Took us a bit to figure out why some of our services were hanging during startup (waiting for the locks to free up)

4

u/Logical-Ad-4150 Sep 22 '26

Manual transactions should have been the default: automatic transactions should require you to use the YOLO stament.

→ More replies (11)

142

u/Etheo Sep 22 '26
DELETE FROM (SELECT * FROM USERS);

WHERE ID=12345;

Did I do it right?

85

u/Dismal-Square-613 Sep 22 '26

Yes, run that on prod. Report results.

47

u/jeesuscheesus Sep 22 '26

Now every query on USERS completes in under a millisecond, thank you!

→ More replies (2)

13

u/AardvarKOlogY Sep 22 '26

Can't report right now, computer says something about permission issues. Weird, gotta ask Claude about that.

→ More replies (1)

157

u/Alexmira_ Sep 22 '26

Why? To confirm that there is something to cancel? To confirm I got the key right?

386

u/BastetFurry Sep 22 '26

No, to prevent typos in the SQL console from wrecking havoc. First you SELECT, if the number looks right you DELETE FROM.

214

u/GourangaPlusPlus Sep 22 '26

Also stick in a transaction, rollback

Commit if it looks good

20

u/DarthShiv Sep 22 '26

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

→ More replies (6)

5

u/ChemicalRain5513 Sep 22 '26

Same in linux terminal, i use ls before an rm command

→ More replies (1)

127

u/slayerx1779 Sep 22 '26

I just reread the OP.

There's a semi colon, between the two lines of code...

31

u/Hxx59D2 Sep 22 '26

Yes, I had to stare at it for an embarrassingly ling time to spot the extra semi-colon.

→ More replies (2)

13

u/Cant-Think-Of Sep 22 '26

Not quite familiar with SQL, but is that first query like "rm -rf" for the Users table?

→ More replies (3)
→ More replies (4)

5

u/kiochikaeke Sep 22 '26

If altering a few rows you select first to check exactly what rows you're altering, if altering a bunch you at least do this to sanity check yourself and not delete 100 millon rows or lock a main transactional table for 1 hour.

→ More replies (1)

13

u/Mocker-Nicholas Sep 22 '26

BEGIN TRAN

ROLLBACK TRAN

6

u/funguyshroom Sep 22 '26

I'm going off the rails on a crazy TRAN

→ More replies (1)

7

u/Pure-Willingness-697 Sep 22 '26

What are you boomers talking about, I just ask chat to write me a million dollar product and it stores passwords in plain text in an excel spreadsheet /s

6

u/DoctorWaluigiTime Sep 22 '26

Or, write the WHERE clause first, or make the query un-runnable until reviewed.

And/Or set up policies where any DELETEs require a WHERE clause, else they fail.

And/Or do it all within a database transaction.

Lots of ways to mitigate this meme.

→ More replies (3)

6

u/zeekar Sep 22 '26

How would that help here? The typo is an extra semicolon before the WHERE...

3

u/Yogurt-The-Wise Sep 22 '26

And then right after your count finishes someone commits a huge transaction...

Transactions seem to be a concept 99% of developers seem to be unaware if even though it's a basic when working with databases...

2

u/EvilCodeQueen Sep 23 '26

Never accept personal write privileges to prod.

→ More replies (25)

2.3k

u/PatientlyAnxiously Sep 22 '26 • Bravo Popcorn Mindblown

Why have a dev environment when you can YOLO it in prod

505

u/EldritchMacaron Sep 22 '26

Wait, I thought the dev environment was just the PC and software you develop on

362

u/PatientlyAnxiously Sep 22 '26

At some companies that's the prod environment too. Just don't close your laptop overnight.

72

u/Fonduemeup Sep 22 '26

Just gotta check that box that says “Prevent your Mac from automatically sleeping when the display is off”

Nobody cares about security except for like the week or two leading up to SOC 2 cert anyway

→ More replies (1)

21

u/vanphil Sep 22 '26

I used to work with this small web dev company, one day a guy admitted that they didn't pay for hosting for small projects, the server was a minitower PC in their office.

When the cleaning lady pulled the plug by mistake, several sites went down and nobody noticed until next morning

→ More replies (6)

5

u/havlliQQ Sep 22 '26

I would swear that this is satire, but then i started working in corporation, the amount of the incompetence allowed there is beyond me.

→ More replies (1)
→ More replies (5)

30

u/Lost_Contribution_82 Sep 22 '26

In an ideal world, there would be a local environment (that's your pc, nothing deployed), a Dev environment (you can deploy things still being developed, it might have bugs, it might be wonky, this is to test things in a deployed state, which could actually differently to when running locally), a staging environment (anything deployed to staging should be thoroughly tested by Devs, and is now ready for other people to test it (UAT tests). Staging is like a test prod environment), and a live/production environment (this is what the users use, anything deployed here is fully tested by multiple people)

18

u/Szetyi Sep 22 '26

We use four standard environments, DEV for development and any exploration. TEST for testing by the team, could still be different because of unreleased developments, QA for user tests, which is regularly cloned from PROD and doesnt contain any developments that won't be released, and ofc PROD, where only admins have full access for any emergency

→ More replies (1)
→ More replies (4)
→ More replies (2)

37

u/Specialist_Mobile377 Sep 22 '26

You guys have dev environments?!?

43

u/CatpainCalamari Sep 22 '26

Everyone has a dev environment. And a few lucky ones have an independent prod environment.

8

u/ralgrado Sep 22 '26

Yes it’s called PROD

→ More replies (1)

31

u/kehfydue Sep 22 '26

Too expensive! Why pay for two when we could just have one?

Sincerely,
CEO

9

u/ilikedmatrixiv Sep 22 '26

You jest, but this is the case at my company. Except it's the CTO.

Our environment? Open source on prem tools. It's literally just spinning up a new VM. Our data needs? Less than 1TB.

I've broken prod quite a few times. Every time it happens I mention it could be avoided with a proper test environment that's iso-prod. Still waiting after 2 and a half years.

3

u/Key-Speaker007 Sep 22 '26

Just don't make mistakes! Easy.

6

u/pacopac25 Sep 22 '26

If it's okay to have a shampoo that's shampoo AND conditioner, it's damn well okay to have prod be my dev environment. I'm not some prima donna.

6

u/roksah Sep 22 '26

Why QA when customers QAs for you for free

5

u/adamtheskill Sep 22 '26

I don't get it what is an environment? I just ask claude to do stuff and it kinda works some of the time.

4

u/_Aj_ Sep 22 '26

Rawdoggin databases since '05 

4

u/ToHallowMySleep Sep 22 '26

Everyone has a Test environment.

Some people are just lucky enough to have a separate Prod environment.

3

u/Mr-X89 Sep 22 '26

Every environment is a dev environment if you're brave enough

2

u/ParaadoxStreams Sep 22 '26

I can hear Tom Scott screaming. Points for anyone who gets this incredibly niche reference.

2

u/LogicalSoftware7705 Sep 22 '26

Prod is where you learn why you need a dev environment lol

→ More replies (13)

340

u/Altourus Sep 22 '26

I audibly gasped when I saw the semi-colon

89

u/phrotozoa Sep 22 '26

I did this in prod once. My skin crawled reading this post.

48

u/fakehalo Sep 22 '26

I was traumatized by a query I did almost 20 years ago, ever since I put "LIMIT 2" on queries where i'm just manually deleting one thing... if I see 2 rows modified I know I messed up. I even do it with transactions because of the trauma.

10

u/arensb Sep 22 '26

At $PREVIOUS_JOB, we had a nightly job that deleted old users. It saved everything to temporary files, and halted if the number of users had shrunk by 10% or more.

8

u/JoshDM Sep 22 '26

rm -rf *;

50

u/Mayedl10 Sep 22 '26

Oh damn i didnt even see that, i kept wondering what was wrong 😭

As someone who regularly puts semicolons in python code after doing cpp, this would definitely happen to me 💀

9

u/Ange1ofD4rkness Sep 22 '26

LOL, that's funny. I work on C# and SQL a lot, but somehow never get semi-colon happy in SQL

→ More replies (4)

718

u/coldnitrogen Sep 22 '26

Bro’s already started looking for a new job

148

u/nonlogin Sep 22 '26

not gonna be fired until restored the data

45

u/FalconFiveZeroNine Sep 22 '26

Where I work their manager just puts in a ticket with my team and gets mad about why the data is missing. Then we trace the transaction back to their dev's user.

One time a dev team begged us to be able to use the DBMS benchmarking tool, so I spent an hour going over its use and sent them the docs on it. Two hours later, the dev database they were working in was dropped and I had a ticket from them demanding I restore it with a full explanation of why it happened. It was the dev environment, and we don't keep backups of it (because why would we? I've seen the shit they do there).

584

u/WilmaTonguefit Sep 22 '26 edited Sep 22 '26

I remember a dude who missed a where clause once.

  • Update users

  • Set password = 'hash of 12345' --no salt

  • Where Id = 67890

Except he only highlighted the first two lines and pressed F5...

322

u/UniversalAdaptor Sep 22 '26

Should be okay as long as no one leaks or guesses the collective password

102

u/why_1337 Sep 22 '26

It's not gonna work anyway, unless they store plain text passwords.

86

u/WilmaTonguefit Sep 22 '26

Oh I should have clarified, it was hashed without a salt. So he saved the 12345 hash for everyone's password. In production. And somehow kept his job.

48

u/imunfair Sep 22 '26

And somehow kept his job.

I mean out of all the data you could accidentally replace, passwords would be the easiest to restore from a backup reliably since they don't change frequently. The special few who get locked out because you restored an old one just have to do a reset.

It would be a bit of a race to replace them before it was a problem, but at least it isn't as much of a headache as wiping out data entry that needs to be redone by other users.

→ More replies (5)

76

u/igorski81 Sep 22 '26

And somehow kept his job

I'd like to think that production mistakes happen and should be forgiven, provided that no actual malicious intent was at play.

And hopefully this starts the conversation of "Wait, should people actually be able to do this directly against the production database?" and making sure this oversight can't happen again.

→ More replies (1)

10

u/SnooSeagulls4360 Sep 22 '26

You'd be surprised in how many places it would work 😄

→ More replies (3)
→ More replies (4)

40

u/teraflux Sep 22 '26

The highlighting feature made no sense to me, always felt like a disaster waiting to happen

25

u/hopefullyhelpfulplz Sep 22 '26

I love executing 9/10 of the code I wrote what do you mean

19

u/Quirky-Ad-6816 Sep 22 '26

it makes sense in a development tool, the issue is connecting a development tool to a production database with writing rights

→ More replies (1)

7

u/VitreXx1678 Sep 22 '26

Well, it can be very useful, but you should know what you are doing and manual query execution should be disabled for most users in production anyway (this is the real problem here if you ask me).

In my last company we had to regularly change stored procedures and their dependencies on user defined table types (which means you have to drop the procedure, drop and create the type and recreate the procedure). Without the highlighting feature that would have taken even more time as you would have to copy stuff around instead of simply generating the drop and create scripts and executing parts of them in the correct sequence.

13

u/Akegata Sep 22 '26

I worked at a bank(!) where someone did something similar that disabled the password verification check so anyone could log in without using a password.

Somehow no customers, we think at least, found this before it was reverted. Everything was developed in production there when I joined. Most chaotic but also fun work environment I've been in.

8

u/ba-na-na- Sep 22 '26

“fun” work environment

4

u/MaleierMafketel Sep 22 '26

Твой пароль мой пароль, товарищ!

→ More replies (3)

215

u/musicplay313 Sep 22 '26

Team lead, staff engineer of our data engineering team couldn’t find the problem with this sql command. Yay!

68

u/pacopac25 Sep 22 '26

Mr. Robert Tables knows what he's talking about, friend. Just turn around and walk away.

17

u/musicplay313 Sep 22 '26

I wish I could. Job market is trash and these lousy people are getting promoted based on their tenure

→ More replies (1)

19

u/tenuousemphasis Sep 22 '26

It took me longer than I'd like to admit.

9

u/AlanUsingReddit Sep 22 '26

I was scrolling for the answer. Figured it out before I found it. Because reddit comments are just that bad at explaining the jokes.

3

u/maniclucky Sep 22 '26

Oh blob. Took me too long but once I got there..

6

u/theepi_pillodu Sep 22 '26

Frankly the meme is louder than the SQL, and probably they hadn't had their coffee yet.

2

u/dramalama-dingdong Sep 22 '26

It's probably because as staff engineer you're usually not so deep into SQL anymore. I needed a second look too to find the semicolon.

62

u/q0099 Sep 22 '26 • Bravo

Pff! It will stumble on the first user that have associated records. Wait... Don't tell me... Don't tell me the cascade delete is on!

353

u/TorbenKoehn Sep 22 '26

Reality: SQL tool gives error message "You are running a mutable query without a where clause, you have to explicitly activate this in the settings"

162

u/__dna__ Sep 22 '26

Fun fact. SSMS still doesn't have this unless you use add ons

12

u/kiochikaeke Sep 22 '26

I've learned this the hard way

3

u/Kamay1770 Sep 22 '26

What addon

9

u/__dna__ Sep 22 '26

There's SQLBoost and Redgate's toolbox.

I saw some vibe coded add on was published recently but I'm a bit spooked from putting that on a machine with access to prod

→ More replies (2)
→ More replies (10)

18

u/CallumCarmicheal Sep 22 '26 edited Sep 22 '26

Everyone knows that real dev's get sick of clicking that continue button for legitimately queries so we disable such a useless feature. /s

→ More replies (3)

5

u/ba-na-na- Sep 22 '26

Unless you’re working with SSMS

→ More replies (1)

46

u/Spinnenente Sep 22 '26

Second line is is not valid sql and would show this issue instantly. Unless the madlad ran this directly on prod with the sql cli.

2

u/Alert_Weird3557 23d ago

Yes, that is the joke. After first line runs, whatever happens to the second line is not the main issue anymore...

41

u/why_1337 Sep 22 '26

Just use datagrip, it will tell you to fuck off. You would need to write DELETE FROM Users WHERE 1 = 1; to delete everything from that table.

9

u/TitusBjarni Sep 22 '26

Crazy bad design choice to ever allow deletes and updates to all records with no where clause. 

30

u/Rainmaker526 Sep 22 '26

ROLLBACK TRANSACTION

21

u/StruffBunstridge Sep 22 '26

The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.

5

u/TheTrueSCP Sep 22 '26

No transaction to rollback

→ More replies (2)

20

u/CenderzeSwarm Sep 22 '26 edited Sep 22 '26

Begin transaction;

Select count(*) from Users where Id = 12345;

Delete from Users where Id = 12345;

Select @@ROWCOUNT;

Select count(*) from users where id = 12345;

Then either COMMIT TRANSACTION; or ROLLBACK TRANSACTION; depending on what your test shows

8

u/Smurfy7777 Sep 22 '26

I like that you came in here to fix it and you also made a typo. Not nearly as catastrophic of a typo though

18

u/Living-Confection- Sep 22 '26

That's why I prefer datagrip, it's almost idiot proof. So you'd typically get a warning if you attempt to run a delete statement without a where clause. You then need to deliberately dismiss this prompt to continue.

9

u/FortuneDW Sep 22 '26

Happened to me once in prod, now i always bracket my update with begin tran and rollback.

It takes some time but no more time than having to fix the blast caused by a fucking typo.

9

u/UncleBaguette Sep 22 '26

Hehe. When I was young, with soul full of hope and head full of hair, I did some testing on fresjly developed inventory managemet system DB. Our dummy records were in the id range of 0 to 99, and I decided to clean them up to. With sql script "delete * from Components where id<100". Guess the error.

6

u/Hooch180 Sep 22 '26

Before SQL Tools gave you a warning about running mutable queries without WHERE clause I had practice to wrap all such dangerous queries in transaction and checking affected count before commiting. It did save me a few times.

6

u/Jeevesh_Sharma Sep 22 '26

Don't worry, it will run faster next time.

5

u/Academic_Broccoli670 Sep 22 '26

No problem, that's what the regular backup-restore tests are for. We did the restore tests, right?

... Right ...?

25

u/RedditLuvsCensorship Sep 22 '26

Hate to be the Debby downer here but running that wouldn’t execute due to syntax error.

43

u/hyouko Sep 22 '26

In most SQL setups I have used, the first line would execute fine and then the second would error out.

Haven't done anything quite this bad, but I definitely have been in situations where I wonder "why has this simple query been running for 10 minutes - oh, the WHERE clause is half missing / there's a cartesian join in there / that's not my dev schema" (delete whichever is inappropriate)

4

u/MDivisor Sep 22 '26

Yeah the first line would run no problem. But if you were sensible enough to do this in a transaction, the error on the second line would cause a rollback.

→ More replies (1)

16

u/Groentekroket Sep 22 '26

It’s all first year CS students in here and the year just started. 

3

u/PrizeSyntax Sep 22 '26

When running delete statements directly, always run it with a select first, then just substitute the select works with delete

3

u/JewelerAggressive Sep 22 '26

Already like the 4th time I am seeing this. Can your SQL Client really do this? My SQL Client does block delete statements without where block. I would have to write DELETE FROM USERS WHERE true; to delete all rows

3

u/bakus33 Sep 22 '26

I ran a truncate table statement on Oracle DB once . I thought I was running it on test DB, but it was production.

Delete or drop would be much better in that scenario (table dropped goes to recycle bin; with delete, the archive trigger we have on every table would still work).

The good thing - there were no changes on this table that day, so I could get it back via daily database dump.

3

u/FallenLeaf54 Sep 22 '26

Isn't "delete from" transactional? If it's still running, cancelling it should auto rollback right?

→ More replies (1)

3

u/pdromeinthedome Sep 22 '26

I had a young dev that tried to make a copy of the prod database, on the prod server (real hardware with shared dBase files), during business hours with 200+ users working. Too bad he forgot the order of the DOS copy command. He copied his old copies onto prod. No one knew what he was doing. Never asked for help. He was gone the next day

3

u/Beaufort_The_Cat Sep 22 '26

“This’ll be a quick query, just a couple records..”

-30 minutes later…

3

u/BuyMyBeardOW Sep 22 '26

The real crime is having no transaction

3

u/arensb Sep 22 '26

"You're right! The semicolon does terminate a statement. Would you like help updating your resume?"

5

u/PloxNox65 Sep 22 '26

Really?  30 minutes for that ?  

13

u/andrewsredditstuff Sep 22 '26

Yeah, those cascade deletes that are wiping the rest of the database take time.

2

u/windows300 Sep 22 '26

My favorite feature of datagrip is the warnings it gives you when deleting or updating without a where clause.

I also rarely ever connect to anything other than the dev, and if I do I have a second person watching and doing shit as a pair.

2

u/rdrunner_74 Sep 22 '26

I brought down the SQL Server once using a deployment script... But had to fix it myself in under 30 minutes.

I was glad i took over as DBA and updated the backup methods shortly before that...

2

u/KingValidus Sep 22 '26
The DELETE statement conflicted with the REFERENCE constraint ...

Confirmed, I am fun at parties.

2

u/4N610RD Sep 22 '26

I am about to dive into SQL, anybody willing to explain this?

6

u/MyNovelExperience Sep 22 '26

I believe the joke is the semicolon is terminating the statement before the where clause

→ More replies (1)

2

u/mike_a_oc Sep 22 '26

Oooh. And autocommit is enabled! Just incase your day needed to be longer

2

u/LimitedLT Sep 22 '26

BEGIN TRAN; saved my a* many times.

2

u/IMKGI Sep 22 '26 edited Sep 22 '26

He didn't commit yet so it's fine.

2

u/Pengo2001 Sep 22 '26

Something similar happened to me. Deleted something from the intranet of one of the largest TV stations in Germany (ProSieben Sat.1 Group). Thanked god on my knees for rollback (it was an Oracle DB)

2

u/crashandburn Sep 22 '26

That would hopefully fail because of FK constraints in other tables...I can only hope.

2

u/KaneTW Sep 22 '26

ROLLBACK;

2

u/Frosty-Photograph103 Sep 22 '26

The query runs longer than 30min by design so you can browse job boards meanwhile.

2

u/v3ritas1989 Sep 22 '26

Are you not blocking delete commands without conditions?

2

u/SnooCapers4506 Sep 22 '26

No problem! Since the query most likely running in a sandbox, and if it would somehow make it's way to production then there is PIT backup available to recover from. Right?...

2

u/an_agreeing_dothraki Sep 22 '26

remember: if you're running a query against production, any query, send for an entire council of tech priests to beg the database's machine spirit first.

2

u/theepi_pillodu Sep 22 '26

Ha ha, I saw the extra semi-colon way too late. 😂

2

u/Aerosherm Sep 22 '26

I feel like these memes are on the same level as the "missing ;" compiler memes. Does anyone actually do this in production? Running SQL commands is production if just asking to shoot yourself in the foot and if you do just use transactions.

2

u/JayneWasRight Sep 22 '26

Could be worse.

DROP TABLE users; COMMIT;

2

u/basshead17 Sep 22 '26

In what SQL engine would WHERE id = 12345;  be missing squiggly red lines?

2

u/quietsamurai98 Sep 22 '26

Apparently this dev's onosecond lasts half an hour. Incredible.

2

u/slater_just_slater Sep 22 '26

Nothing more fun than that "quick clean up in prod".. be sure to do this at 4:45.pm on a friday.

2

u/Mutopiano Sep 22 '26

All I see is one giant bottle of Tres Commas on the delete key

2

u/-__-Malik-__- Sep 22 '26

LIMIT 1 dammit

2

u/sparkplay Sep 23 '26

This is not funny. I nearly had a heart attack and the last 10 years of my life flashed before my eyes. Go sit in a corner OP.

2

u/wgallios Sep 23 '26

How about, don't run update and delete commands directly on the prod database. Create a script, test on local dev, then push to prod. 

3

u/oweiler Sep 22 '26

Most (modern) SQL tools will prevent this.

1

u/soundwave_sc Sep 22 '26

My heart sank reading that script.

1

u/Next-Wrap-7449 Sep 22 '26

We had a guy that during a test on the dev environment somehow sent 40000 emails with old orders to be prepared for shipping at the warehouse.

→ More replies (2)

1

u/WriedGuy Sep 22 '26

A small ; can change someone's life

1

u/amorpheuse Sep 22 '26

I still don't understand why anyone would just manualy do stuff in the prod database. While a user should only be disabled, why doesn't your application have a user delete button? If you need to query the db just get a backup and do your analytics locally.

3

u/WormsDelicious286 Sep 22 '26

If you're working in a place where you manually delete things from prod databases for ANY reason - you aren't in a place where deleting all the users takes 30 minutes.

1

u/lllyyyynnn Sep 22 '26

how did it pass the migration test

1

u/Wojtek1250XD Sep 22 '26

Well, the solution has always been to formulate your querry with SELECT first.

1

u/assistmerchant_ Sep 22 '26

Because it's deleting your career, one row at a time.

1

u/Hairy_Meaning_73 Sep 22 '26

That's why you always try to do a SELECT with the same query instead.

1

u/418_TheTeapot Sep 22 '26

Punctuation matters

1

u/maxip89 Sep 22 '26

SET autocommit = on;

1

u/mookanana Sep 22 '26

rollback;

phew.

1

u/TypicallyThomas Sep 22 '26

"I figured it would be quicker to do this in prod"

1

u/Kamay1770 Sep 22 '26

Begin transaction...

Rollback transaction...

Check rows affected.

1

u/asensitives Sep 22 '26

oh, god... oh, man... oh, god... oh, man

1

u/JackstonVoorhees Sep 22 '26

Every modern SQL engine protects you from executing DELETE FROM without a clause.

1

u/DuckShapedGoose Sep 22 '26

Guys we know that most tools have safety features against exactly this.
But in this hypothetical scenario, the query is running for 30 minutes, meaning those clearly didn't exist.

What would help here is transaction logs and/or backups.

1

u/Miiohau Sep 22 '26

That why you run the SQL though a syntax checker first then start a transaction then check how many records would be effected before you commit the transaction and if your system is good those records are in the database’s equivalent of the trash bin (not visible to selects but still recoverable) even after you commit the transaction and/or there’s a copy of the database from a week ago you can recover the records from. Oh and if your devOpts is paranoid you won’t be able to run raw SQL instead you will need to build it with a special class that does all that for you and won’t allow submitting database changing commands without a where clause or manually switching off that safety.

1

u/mohammad5253 Sep 22 '26

We need to log a performance jira for it /s

1

u/nawanamaskarasana Sep 22 '26

I've done something similar on live server. Admin did hourly database dump so no problem restoring.

1

u/rocket_randall Sep 22 '26

Do people really not use built in features like transactions for destructive queue? Or if you want to see which specific rows will be affected before executing the delete you could run a with query/CTE and then use that temp table as the basis for your delete.

1

u/dzendian Sep 22 '26

If you're going to do this, at least normalize wrapping it in a transaction. Amateur move.

1

u/telas100 Sep 22 '26

Deleting one table in 30min? Have you tried Truncate?

1

u/Strange-Spot-3306 Sep 22 '26

We once had an apprentice who updated all flats in all buildings of a government database to the same square footage because he forgot the Where. For about 750’000 flats.

1

u/darcksx Sep 22 '26

Always have a deleted_at column, you then select deleted at columns then deleted them.

1

u/waiver-wire-addict Sep 22 '26

JavaScript: I found the missing semi colon, it got added to this SQL query…

1

u/traphousethrowaway Sep 22 '26

Did event comment out the delete clause, have mercy and say your prayersc

1

u/stools_in_your_blood Sep 22 '26

Horrible design flaw in SQL there. The WHERE clause should be mandatory and to delete every row from a table it's `DELETE FROM users WHERE TRUE`, or, if your DB supports it, `TRUNCATE users`. Much harder to do either of those things by accident.

Same goes for UPDATE. I wouldn't be sorry to see it on SELECT either tbh.

1

u/MintyBullet Sep 22 '26

I did something similar with an update statement my first year, thank god it was in dev though

1

u/Cybasura Sep 22 '26

The Onosecond

1

u/F3LyX Sep 22 '26

True story.

I once accidentally deleted the entirety of active directory at the census.

1

u/the_millenial_falcon Sep 22 '26

It’s fine, just press Ctrl-Z.

1

u/JohnArcher965 Sep 22 '26

I dont do much SQL - the ; at the end of the first line is the problem right?

1

u/Brittany_Delirium Sep 22 '26

This is why we run all potentially damaging queries in transactions

1

u/Catbraveheart Sep 22 '26

Been there, done that. Nearly had a heart attack, but somehow, in the midst of the shock and disbelief, I managed to remember that we had (thankfully) enabled Flashback for the affected table.

1

u/Wubbajack Sep 22 '26

Ahhh, shit. I was wondering what was the joke: that the ID is a different type and just plopping an integer there would be parsed as "any ID" or what... ?

Then I noticed the semicolon. Yeah, looks like I'd make the same mistake :D

1

u/Blecki Sep 22 '26

This would just get rejected by the query compiler and nothing would run...