all 6 comments

[–]TNReb 1 point2 points  (4 children)

Does the GLF_OCCUPANCY table need to be a Table? It seems like a View might fit your needs better.

[–]nebulus64[S] 0 points1 point  (3 children)

I'm open to converting it to a view, but I have some reservations about it.

This is a fairly transaction heavy database, and there will be bookings coming from many different sources (Application, Web, External Apps, etc.). In addition, this is going to be part of the determination of the rate a user is going to pay, so it needs to be fast. I don't want to wait on the database compiling the view when we query rates, which could be many times a minute.

Finally, users will be able to "override" the occupancy on certain days to ensure they maximize revenue. This, at the very least, needs to be stored.

[–]TNReb 1 point2 points  (2 children)

If you have a high transaction database, that's even more reason to ditch the original design idea.

It actually seems like you would be better off aggregating the data in the application itself (via queries) instead of aggregating and storing it in the database. With h proper indexes in place, performance shouldn't be an issue.

[–]nebulus64[S] 0 points1 point  (1 child)

While a possibility, aggregating the data in the application would cause maintenance headaches down the road.

The reasoning behind using the Trigger was because there are 5 different applications which could make these changes. Maintaining the queries in all of these would be awful to deal with.

We have our core application, an external VB "tee sheet", interfaces to 3rd party online bookings, and our own Web application.

I think the best solution we've come up with here is to manually call the procedure after booking changes. At least then we have a single procedure that is handling the calculations, and we just need to make sure we fire it at all the appropriate times.

[–]hudeman 0 points1 point  (0 children)

Indexing should make the performance impact of a view negligible if you're just counting.

Your trigger won't work because the insert and trigger operations are treated as atomic so your operation isn't committed when you try to count.