DELETE FROM
Customers WHERE
Name='Gude' AND
Area='Tama'
;
Much harder to leave off half the clause doing this kind of thing.It doesn't save me time, but a lot of nerves.
SELECT *
-- DELETE
FROM Sales
WHERE Customer = 1
Next, selecting the whole query and executing it. If results are satisfactory - selecting only the DELETE part. select * -- delete
from sales
where customer = 1
so it's even harder to accidentally highlight the 'delete' part.Although I've switched to DBeaver for a year now, and it automatically pops up a warning when it detects a DELETE query without a WHERE, which is very nice.
Then if you make an error you can always ROLLBACK. If it looks OK -- COMMIT.
Similarly `git push ... -f` etc.
Everything is non-destructive without an explicit COMMIT.
--safe-updates
to avoid queries running without WHERE clause.
If you type just a table name into an empty cell it will autocomplete with a full SELECT statement. e.g. if you typed "pubuser" and selected "public.users" it would autocomplete with:
SELECT pu.*
FROM public.users AS pu
WHERE 1=1
Disclaimer: I built this.This is absolutely right. In fact, my ideal query language would require the programmer to be explicit if they want to increase the cardinality of the result set. Meaning, if I start a query with "from Employee ..." the query language should not let me accidentally add a join that will cause the result set to contain the same Employee more than once. (It should be possible, but only if I make it clear that it is intentional and not an accident.)
Yep. As developers/designers we need to understand this as much as we wished our clients did.
Even sooner than "start with FROM" is "What does each row of the result mean?" Is it a sale? A month of sales? A customer? If you can answer what you want, then it's usually easy to start there. Especially if your answer corresponds to an existing table, put that in the FROM, and then add whatever joins you need. You can even think about the joins "imperatively".
Thinking imperatively about JOINs is also a helpful way of understanding a mistake I call "too many outer joins", which I wrote about here: https://illuminatedcomputing.com/posts/2015/02/too_many_oute... If you don't know about this mistake, it's easy to get the wrong answer from aggregate functions like AVG or COUNT. (EDIT: I should probably call this "too many joins" instead, since it's not really specific to outer joins. But in practice I find outer joins are more often used in these sort of situations.)