What to name column in database table that holds versioning number
Posted
by rwmnau
on Stack Overflow
See other posts from Stack Overflow
or by rwmnau
Published on 2010-01-08T19:44:24Z
Indexed on
2010/05/18
2:40 UTC
Read the original article
Hit count: 289
I'm trying to figure out what to call the column in my database table that holds an INT to specific "record version". I'm currently using "RecordOrder", but I don't like that, because people think higher=newer, but the way I'm using it, lower=newer (with "1" being the current record, "2" being the second most current, "3" older still, and so on). I've considered "RecordVersion", but I'm afraid that would have the same problem. Any other suggestions? "RecordAge"?
I'm doing this because when I insert into the table, instead of having to find out what version is next, then run the risk of having that number stolen from me before I write, I just insert insert with a "RecordOrder" of 0. There's a trigger on the table AFTER INSERT that increments all the "RecordOrder" numbers for that key by 1, so the record I just inserted becomes "1", and all others are increased by 1. That way, you can get a person's current record by selection RecordOrder=1, instead of getting the MAX(RecordOrder) and then selecting that.
PS - I'm also open to criticism about why this is a terrible idea and I should be incrementing this index instead. This just seemed to make lookups much easier, but if it's a bad idea, please enlighten me!
Some details about the data, as an example:
I have the following database table:
CREATE TABLE AmountDue (
CustomerNumber INT,
AmountDue DECIMAL(14,2),
RecordOrder SMALLINT,
RecordCreated DATETIME
)
A subset of my data looks like this:
CustomerNumber Amountdue RecordOrder RecordCreated
100 0 1 2009-12-19 05:10:10.123
100 10.05 2 2009-12-15 06:12:10.123
100 100.00 3 2009-12-14 14:19:10.123
101 5.00 1 2009-11-14 05:16:10.123
In this example, there are three rows for customer 100 - they owed $100, then $10.05, and now they owe nothing. Let me know if I need to clarify it some more.
UPDATE:
The "RecordOrder" and "RecordCreated" columns are not available to the user - they're only there for internal use, and to help figure out which is the current customer record. Also, I could use it to return an appropriately-ordered customer history, though I could just as easily do that with the date. I can accomplish the same thing as an incrementing "Record Version" with just the RecordCreated date, I suppose, but that removes the convenience of knowing that RecordOrder=1 is the current record, and I'm back to doing a sub-query with MAX or MIN on the DateTime to determine the most recent record.
© Stack Overflow or respective owner