Worst SQL Ever?
Worst USE of an SQL query every:
A SELECT query that that counts the number of lines corresponding to a certain condition, called in the stopping condition of a for loop.
Something like this:
for(int i = 0; i < query("SELECT COUNT .... WHERE ..."); i++)
{
}
And no, the result of the query doesn't change every iteration. Yes I realize the server is going to cache the result.
DELETE FROM table
Seen right after I typed and executed it, I had forgotten the WHERE clause. Now I always run a SELECT statement first and change the SELECT to DELETE after I am satisfied that the proper rows will be affected.
The classic xkcd of course:
WHERE name = ROBERT'); DROP TABLE students;--