DEV Community

ToolGBRMaker
ToolGBRMaker

Posted on • Originally published at toolgbrmaker.wordpress.com on

Quick Tip: OUTPUT clause – Good Policy | SQL

Let’s check how the OUTPUT clause can save the day if we, after an update, may want to revert what has been updated.

Imagine that we have the following output from a customer table on the SQL:

And we decided to switch all the customers with the first name “Antonio” to “António”. A simple update query like the following could achieve what we’re looking for…

Now, happens something completely unexpected in the TI world (or not!!!)… Well, customers are not pleased with their name change and want to get them back on our database. But which ones have been changed?

Time to use the OUTPUT clause on our update queries. If you use it, you’ll get an output of all the entries that have been changed and back up that information to be reused after, if needed. See the next example of how can be used on the above example:

Now, you can copy, save, extract, etc., your result to backup file and use it whenever needed.

Stay safe!

Top comments (0)