Sql-server – Where to store versioned/historized records

data-versioningsql-server-2012

In our application we are using versioning records using triggers. The application is supposed to handle millions of records in the future and the history/versioning tables are there to ensure that there is an audit trail for various transactions.

Currently everything is stored into one database. My concern is that these tables will bloat the transactional database, and I really want to move all record history into another database mainly because:

  1. transactional database can be backed up more frequently since it is smaller.
  2. indices can be scheduled to be rebuilt more frequently on the transactional db.
  3. The history can be archived more easily if needed.

Are there any performance advantages to choosing this strategy or is the extra database another moving part which is not needed? What is the prescribed solution for this sort of thing?

Best Answer

We use Change Data Capture. SQL Server essentially creates journal tables and then automatically reads from the transaction log and fills in the journal tables with information about DML operations on the original table.

To save space, we compress the journal tables. This means your journal tables are stored in the same database, but if you are having space issues, you could offload them to a different file/filegroup and store that on a different disk.

The journal tables are in a separate schema so you could exclude that entire schema from your short-term backups and only include them in your long-term backups.