How to access Historical Data using Time Travel in BigQuery
Restore and Analyze deleted or changed Data

In case you haven’t heard about it — For some time now, BigQuery has been offering time travel to access stored data that has been modified or deleted. You can access the data at any point in time within the last seven days. You can use time travel to retrieve data that has been updated or deleted, restore a deleted table, or restore a table that has expired.
I think it’s a super handy feature because it comes out of the box and allows you to view the history of data, which can be interesting for compliance but also to understand business processes or even to detect fraud. Provided of course that the seven days are enough. For the use case that you have accidentally deleted something should be enough in any case. However, if you want to keep data and the changes to it longer, there is either the possibility to create snapshots [1] or to realize the whole thing via versioning [2].
You can do this very easily using SQL. This clause uses a constant timestamp expression and references the version of the table that was current at that timestamp. The table must be stored in BigQuery, so it cannot be an external table.
SELECT *
FROM bigquery-public-data.samples.shakespeare FOR SYSTEM_TIME AS OF TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR);In this example, I applied it to the Shakespeare public dataset. As you can see below you will get the result as usual.

You can then use the result for analysis purposes or, in case of accidental deletion, save it as a table and restore it.
To me, that’s a super cool feature if you’re not already historizing data anyway. But even here it could happen that you accidentally delete this data, now Google offers you to restore this data for seven days. In any case, a plus point in terms of data security.





