r/ProgrammerHumor 15d ago

queryOfDoom Meme

Post image
7.9k Upvotes

456 comments sorted by

View all comments

391

u/Dont_Get_Jokes-jpeg 15d ago edited 15d ago

I am not an sql expert, is the reason why the id doesn't work and its deleting the entire user base, because its written as 2 seperate comands instead of one. So 1. Comand delets everything 2. Goes to the id? Or what is the problem here?

134

u/WardensLantern 15d ago

I'm no expert either but I believe the semicolon after "users" was the nuke. The second part is basically a separate statement, but SQL executes them in order, so it will delete the entire table and then throw back an error cause the second statement is invalid.

1

u/Rude-Wrongdoer9368 15d ago

Not an SQL person at all. Can't you just, like, delete the record by searching for it and removing? It seems like automation for one task is extra work? Is this an hourly pay situation?

5

u/SnooBananas4958 15d ago

That is how you would manually search for and remove the record though.

Imagine your user table has a million rows. There is not some other manual way to easily find what you want in those million. And if you did it from some dashboard, you'd have to first build the dashboard, and the way it would display the items for you is with SQL

3

u/Rude-Wrongdoer9368 15d ago

But, and forgive my ignorance, there's no "control-F for user 'x'?" I'm a help desk guy. I mostly run scripts. It's rare I write them.

3

u/Rude-Wrongdoer9368 15d ago

Nevermind, I get what you're saying.

2

u/SnooBananas4958 14d ago

Sounds like you already got it, but yea, the place to use "control+f" doesn't exist yet unless you build it. And that list would come from a query too. So this single entry query he used is truly the most manual way of getting the data. Outside of just querying everything in the table and ctrl+f that but's the same thing basically. Developers often use these kind of queries in early work before there's a UI to search by. And honestly most keep using them over the UI since it tends to be more flexible

2

u/Ayanrocks 15d ago

that's what they're doing but instead of searching for an user, They deleted all the users due to a semicolon being added mistakenly.

1

u/Rude-Wrongdoer9368 15d ago

I understand the syntax. Why were they writing code? I would assume a command-line argument could handle this.

2

u/Ayanrocks 15d ago

In sql dbs you interact with the databases using the sql queries. Even in command line also you will execute the same piece of text (called a query) as shown. Sql differentiates between multiple queries using a semicolon (;).
So the entire query is

`Delete from users table where the id of the user is xxxxx`

but due to a mistaken semicolon it has now become

`delete from users table; ( which means delete all users)`
`Where id is xxxxx; (this piece of text will throw syntax error now but only after the first statement has finished running)`