Azure Temporal Tables All Vanished
We use Temporal Tables (System Versioned tables) as an audit log of changes to many of our tables, in multiple databases, on a SQL Azure server.
These have been working fine until today.
I just went to access one of them to check on when a change happened, and it wouldn't let me access the ValidFrom and ValidTo fields, nor the System Versioned table.
SELECT *, ValidFrom, ValidTo FROM Clients WHERE sCAccountNo = '0001064'
This fails because ValidFrom and ValidTo don't exist
SELECT *, ValidFrom, ValidTo FROM Clients
FOR SYSTEM_TIME BETWEEN '1753-01-01 00:00:00.000' AND '9999-12-31 23:59:59.997'
WHERE sCAccountNo = '0001064'
ORDER BY ValidFrom DESC
This fails with the error "Temporal FOR SYSTEM_TIME clause can only be used with system-versioned tables. 'DBName.dbo.Clients' is not a system-versioned table."
SELECT * FROM ClientsAudit WHERE sCAccountNo = '0001064'
This fails with "Invalid object name 'ClientsAudit'."
The table is showing the appropriate icon, (System Versioned) on the end of the name, and the Temporal Table "ClientsAudit" underneath it when expanded, all as it should.
So, figuring it was probably a problem with SQL Server Management Studio I restarted it, and tried again.
The table is no longer showing as (System Versioned), and no longer has the Temporal Table "ClientsAudit" underneath it when expanded.
In fact, no tables in the database are showing as System Versioned any more.
In fact, no table in any database on the entire server is showing as System Versioned any more.
Our entire Audit trail on 43 databases gone, wiped out!
So, first question: Why has this happened?
Second question: How can we ensure that this never happens again?
Third question: How can we get our System Versioned tables back?
I tried restoring one of the databases from a couple of days back, just to see, and still none of the tables show as (System Versioned)
Not that restoring 43 databases back a few days would have been a viable solution anyway, of course, but I tested it anyway.
So then I tried turning a table back into a Temporal Table, and that worked
The table has (System Versioned) after it's name, I have the ValidFrom and ValidTo columns, and I have the "TableNameAudit" Temporal Table underneath it when expanded, exactly as before.
I can query the table exactly as before, as shown above, and all the queries work (although obviously the Audit table is empty.
So, it's not that the Azure SQL Server suddenly can't handle Temporal Tables, it's just decided to delete all the ones we previously had!
Which brings me back to:-
First question: Why has this happened?
Second question: How can we ensure that this never happens again?
Third question: How can we get our System Versioned tables back?