Skip to main content
added 303 characters in body
Source Link
Doc Brown
  • 220.3k
  • 35
  • 410
  • 623

Poking holes: what if the database schema is changeschanged at same point later in time, and a column name changes, or the column is deleted completely? Lots of database system allow this. What will happen to your "fieldName" then?

For data integrity: you must make sure that every update or delete operation will for sure update your tracking table. That is best accomplished by triggers calling a stored procedure. You should make sure only those stored procedure has writing access to your tracking table, so noone else can write wrong values.

If you can live with a db vendor specific solution: most db systems have system tables where the schema information (table names, table ids, column names etc) is stored. You can check if it is possible to set a foreign key reference to such a system table. That would allow to replace the field name by a field ID if the database supports something like this.

Actually, if you need to track whole rows of the specific table including all columns (and not just a small subset of the columns), you should consider @sarfeast's suggestion. Read this article about the drawbacks of name-value-pair models.

Poking holes: what if the database schema is changes at same point later in time, and a column name changes or is deleted completely? Lots of database system allow this.

For data integrity: you must make sure that every update or delete operation will for sure update your tracking table. That is best accomplished by triggers calling a stored procedure. You should make sure only those stored procedure has writing access to your tracking table, so noone else can write wrong values.

If you can live with a db vendor specific solution: most db systems have system tables where the schema information (table names, table ids, column names etc) is stored. You can check if it is possible to set a foreign key reference to such a system table. That would allow to replace the field name by a field ID if the database supports something like this.

Poking holes: what if the database schema is changed at same point later in time, and a column name changes, or the column is deleted completely? Lots of database system allow this. What will happen to your "fieldName" then?

For data integrity: you must make sure that every update or delete operation will for sure update your tracking table. That is best accomplished by triggers calling a stored procedure. You should make sure only those stored procedure has writing access to your tracking table, so noone else can write wrong values.

If you can live with a db vendor specific solution: most db systems have system tables where the schema information (table names, table ids, column names etc) is stored. You can check if it is possible to set a foreign key reference to such a system table. That would allow to replace the field name by a field ID if the database supports something like this.

Actually, if you need to track whole rows of the specific table including all columns (and not just a small subset of the columns), you should consider @sarfeast's suggestion. Read this article about the drawbacks of name-value-pair models.

added 304 characters in body
Source Link
Doc Brown
  • 220.3k
  • 35
  • 410
  • 623

Poking holes: what if the database schema is changes at same point later in time, and a column name changes or is deleted completely? Lots of database system allow this.

For data integrity: you must make sure that every update or delete operation will for sure update your tracking table. That is best accomplished by triggers calling a stored proceduresprocedure. You should make sure only those stored procedures haveprocedure has writing access to your tracking table, so noone else can write wrong values.

If you can live with a db vendor specific solution: most db systems have system tables where the schema information (table names, table ids, column names etc) is stored. You can check if it is possible to set a foreign key reference to such a system table. That would allow to replace the field name by a field ID if the database supports something like this.

Poking holes: what if the database schema is changes at same point later in time, and a column name changes or is deleted completely?

For data integrity: you must make sure that every update or delete operation will update your tracking table. That is best accomplished by triggers calling stored procedures. You should make sure only those stored procedures have writing access to your tracking table, so noone else can write wrong values.

Poking holes: what if the database schema is changes at same point later in time, and a column name changes or is deleted completely? Lots of database system allow this.

For data integrity: you must make sure that every update or delete operation will for sure update your tracking table. That is best accomplished by triggers calling a stored procedure. You should make sure only those stored procedure has writing access to your tracking table, so noone else can write wrong values.

If you can live with a db vendor specific solution: most db systems have system tables where the schema information (table names, table ids, column names etc) is stored. You can check if it is possible to set a foreign key reference to such a system table. That would allow to replace the field name by a field ID if the database supports something like this.

Source Link
Doc Brown
  • 220.3k
  • 35
  • 410
  • 623

Poking holes: what if the database schema is changes at same point later in time, and a column name changes or is deleted completely?

For data integrity: you must make sure that every update or delete operation will update your tracking table. That is best accomplished by triggers calling stored procedures. You should make sure only those stored procedures have writing access to your tracking table, so noone else can write wrong values.