Subject | RE: [firebird-support] I need your opinion about table design. |
---|---|
Author | bogdan |
Post date | 2012-10-11T11:00:56Z |
>>Hi guys.never seen before
>>
>>When I came to work for my current company, I saw something that I had
>>(Back then I had 5+ years of experience working with various SQL ServerDBs):
>>updating the row.
>>on each table in database there is a trigger which is fired up before
>>The trigger makes a copy of the updated row and marks it as inactive bysetting field
>>RECORD_ACTIVE = 0. I think that this copy-on-update model is very..verybad.
>>means that we have
>>There is one and only one reason of making such copy, data safety - it
>>history for row changes. We are able to tell what and when had changed.a check in trigger
>>
>>Here are my reasons against it:
>>1. Decreased performance when making updates. In fact, we had to introduce
>>to not make a copy of record if we are importing and updating data viaimport tool because
>>it worked to slow. So I think the whole point of data safety is lostanyway because we can
>>not keep the data safety policy everywhere.Reality conquers theory. Though if you keep the files you are importing,
then I wouldn't say the whole point of data safety is lost, you just have to
look in the imported file rather than in the database if you need to look
back in history (which can be cumbersome, but the data is there).
>>2. Increased table size - decreased performance when reading data.introduced last change
>>
>>3. We have in each table the fields that saying which user( and when)
>>to the record. I think it is sufficient. Our software is not medicalsoftware or banking
>>software, we do not keep so crucial data. There wont be any law suits whensome user will
>>accidentaly change some row. And after all, it is his duty to know what ishe changing.
Maybe management should decide what to keep? One thing is small accidental
changes, but what about changes done to several records due to an employee
not understanding how things should be done? Or an employee trying to steal
from your company (maybe delete customers because he wants to start his own
competing company and contact those customers himself).
>>4. Due to this design I am not able to introduce an unique constraint on acolumn. For
>>example : often there is a need to add unique constraint on a NAME column- I am not able
>>to do this because constraint will fail for the first copy of the givenrecord. (If I
>>create constraint on NAME and RECORD_ACTIVE - constraint will fail onsecond copy.)
>>history of a record
>>5. As long as I am working here there was never a need to check for the
>>in any database. And we have like 100 or more clients...menagement and tell
>>
>>So guys. I am asking you for a fresh point of view. Should I go to the
>>them that this is generally a bad idea or maybe I am wrong? Maybe this isthe way it should
>>be done!?question, except in extreme cases where you can guarantee that history is
>I don't think there is a generally right or wrong solution to this
irrelevant or know that history is as important as the present. It sounds a
bit >over the top to have this on EACH table in your database, e.g. if you
have a COUNTRIES table, then I'd say history is probably irrelevant.
>We do things slightly different that might be a bit more flexible. For ourthree main tables, we have AFTER UPDATE and AFTER DELETE triggers that
copies the old values into other tables that have similar >structure with a
few additional fields. For most other tables we do not keep any history
(well, except daily backups, of course). Such a solution would allow you to
have a constraint on NAME in the main table, but >not on the table with old
values (though you might not want to constrain NAME, in many situations you
could experience the same name not being unique - e.g. there are two
countries named Congo). It wouldn't >help speed-wise regarding imports of
UPDATEs, but INSERTs wouldn't copy anything.
>As for talking to your management, it might be wiser to come up with analternative and say "I've got an idea, let's do it this way" rather than
just saying "I really don't like our system".
>HTH,There is possibly different reason for such design:
>Set
You create an invoice, print it and send it to the customer. After some
time, customer moves to another address.
If you print old invoice again it should be the same as the first time.
The easiest way to achieve this is to keep the history of customer's
attributes under the same ID as it is recorded in the invoice data.
New version of Customer's attributes, gets new ID.
This behaviour can be , of course, achieved in various ways.
Regards
Bogdan
[Non-text portions of this message have been removed]