简体   繁体   中英

Best practice for keeping historical data in SQL (for SSAS Cube use)

I am working on an Hotel DB, and the booking table changes a lot since people book and cancel reservation all the time. Trying to find out the best way to convert the booking table to a fact table in SSAS. I want to be able to get the right statsics from it.

For example: if a client X booked a room on Sep 20th for Dec 20th and canceled the order on Oct 20th. If I run the cube on the month of September (run it in Nov) and I want to see how many rooms got booked in the month of Sep, the order X made should be counted in the sum.
However , if I run the cube for YTD calculation (run it in Nov), the order shouldn't be counted in the sum.

I was thinking about inserting the updates to the same fact table every night, and in addition to the booking number (unique key) and add revision column to the table. So going back to the example, let say client X booking number is 1234, the first time I enter it to the table will get revision 0, in Oct when I add the cancellation record, it will get revision 1 (of course with timestamp on the row).

Now, if I want to look on any piroed of time, I can take it by the timestamp and look at the MAX(revision).

Does it make sense? Any ideas?

NOTE: I gave the example of cancelling the order, but we want to track another statistics.


Another option I read about is partitioning the cubes, but do I partition the entire table. I want to be able to add changes every night. Will I need to partition the entire table every night? it's a huge table.

One way to handle this is to insert records in your fact table for bookings and cancellations. You don't need to look at the max(revision) - cubes are all about aggregation.

If your table looks like this:

booking number, date, rooms booked

You can enter data like this:

00001, 9/10, 1
00002, 9/12, 1
00001, 10/5, -1

Then your YTDs will always have information accurate as of whatever month you're looking at. Simply sum up the booked rooms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM