Has anyone implemented this before? I.e. a change tracking mechanism for a database entity. So we can see different versions of the entity. Just don’t want to reinvent a wheel as it appears to be a common task in software engineering. I am specifically interested in complex entities tracking that include one-to-many and many-to-many relations, I.e. entities which properties are scattered across several tables. Some kind of database level versioning.
Any thoughts?
P.S. I’m using SQL Server 2008 and Entity Framework (code first) as ORM.
Change data capture is a great feature but it’s only available with the enterprise version of SQL Server.
Other things you can try are:
DDL and DML triggers – write triggers for all tables and/or objects you want to track and store previous values in a storage table. This requires a bit of work on your side but it will definitely work. There is a trigger based auditing tool – ApexSQL Audit. You can install the trial, see how triggers are created there and then create something similar for your environment.
Version control – there are 3rd party tools that allow you to version your objects and data and you can probably automate these so you don’t forget to put something in version control. Try SQL Source Control from Red Gate or ApexSQL Version from ApexSQL.
Reading transaction log – if your database is in full recovery mode then almost all data is stored in transaction log (both DML and DDL except for SELECT). Unfortunately, you can only do this with 3rd party tools such as ApexSQL Log or Toad for SQL Server.