Re:SQL queries don't start with SELECT
by brigandish on Friday October 04, 2019 @02:43AM
(#21155386)
Good advice. I also break up the statement so that an incomplete highlight and execute will fail, e.g.
Much harder to leave off half the clause doing this kind of thing.
[ Parent
| on HN ]
I've forced the habit upon myself to first compose a SELECT statement and verify that it will give me exactly the dataset that I want to run my operation on. Then I wrap that statement into a CTE and run the DELETE / UPDATE on the CTE.
It doesn't save me time, but a lot of nerves.
Re:SQL queries don't start with SELECT
by CubicsRube on Friday October 04, 2019 @04:48AM
(#21155924)
I'm used to writing the SELECT query and adding the commented-out DELETE just below the SELECT line.
SELECT *
-- DELETE
FROM Sales
WHERE Customer = 1
Next, selecting the whole query and executing it. If results are satisfactory - selecting only the DELETE part.This is the one I use too. Tiny difference - I write
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.
DBeaver has something even better, albeit sometimes annoying: you can define a connection as "Production" (highlighted red) and "Test" (green). On Production systems, DBeaver will ask you for confirmation for every write statement.