#100DaysOfCode - Day 13: SQL DELETE

#100DaysOfCode - Day 13: SQL DELETE

1 min

Today, I got to work a bit in SQL, and learn how to output elements of a table after they’re being deleted.

In Day 7 and Day 8, we talked about the DELETE statement, which does an action on some rows of a table. Very useful commands!

Well, to expand on those commands, you may want to output the data you’re deleting, as a sort of sanity check to make sure that you only deleted what was expected. Well, how would you do that?

Turns out, it’s pretty simple:

DELETE *
OUTPUT DELETED.*
FROM A
WHERE A.ID = 1

This can be done with INSERT (INSERTED) and UPDATE (UPDATED) statements as well! The trick is just to make sure you have the OUTPUT clause right before the FROM <table> clause =)

~ Moxnr

Written on November 4, 2020