SQL Best Practices - Ok to rely on auto increment field to sort rows chronologically?

后端 未结 7 1405
面向向阳花
面向向阳花 2021-01-01 18:52

I\'m working with a client who wants to add timestamps to a bunch of tables so that they may sort the records in those tables chronologically. All of the tables also have a

7条回答
  •  伪装坚强ぢ
    2021-01-01 19:33

    You can acheive the same goal in the short term by sorting on the ID column. This would be better that adding additional data to acheive the same result. I don't think that it would be confusing for anyone to look at the data table and know that it's chronological when they see that it's an identity column.

    There are a few drawbacks or limitations that I see however.

    • The chronological sort can be messed up if someone re-seeds the column
    • Chronology for a date period cannot be ascertained without the additional data
    • This setup prevents you from sorting chronologically if the system ever accepts new, non-chronological data

    Based on the realistic evaluation of these "limitations" you should be able to advise a proper approach.

提交回复
热议问题