Contents:
Suffice to say for now that the impact to a RDBMS is heavy; most of the concepts that are well-known and that we sometimes take for granted such as Primary Keys and Foreign Keys tend to change drastically the minute that you introduce effective dates into a database schema. Nonetheless, it's still worth the trouble to implement it in the right scenarios, and I will show one such real-world scenario in this article. Although we don't always express this in our database schemas, most data is temporal; it actually only lives over a period of time.
Yet in many tables that we design we don't put in effective dates to signify this.
Many times there is a good reason for this: However, there are times where putting these effective dates in will tremendously help out a project. Unfortunately, many times we don't see this benefit at the start, and our initial design is not effectively dated even though it really is in our best interest. We normally realize this when we find that we need to add all sorts of workarounds just because our system is not date-aware by design. Yet many times we go on blissfully ignoring the effectively dated nature of our business. We keep on piling workarounds, each more ridiculous than the last, on top of a design that is pretending to be eternal, but failing.
This is what I call the "Delusions of Eternity" anti-pattern. It's sort of like ignoring our own mortality we humans are also "effectively dated" , so maybe that is where this attitude comes from. Who knows, but maybe our own mortality tends to put a negative slant on the whole subject of Effective Dating and causes us not to think about it: Let's solidify all of this with an example. Let's say we're designing a database that handles promotions for retail sales in an e-commerce environment. A common design for this is to have a Promotions table which contains all the promotion details and then a 'PromotedProducts' table which links promotions to products.
Below is a simple diagram of this schema:.
So what's the problem here? It seems like a good design at first, but the fact is that Promotions are by definition Effectively Dated, and this design ignores that. Soon the cracks in the design start to appear.
Let's illustrate how this design painfully falls apart:. Yes, you can store promotion details and associate them to products, but what happens when a promotion starts and then ends? You have to switch prices in the products that are affected. So, how do you do this? Well, obviously you run some kind of batch job, at exactly the right time, to change these prices. The batch job would insert the row into the PromotedProducts table at the beginning of the promotion, and then would delete the row at the end of the promotion.
No big deal, right?
Wrong, by several counts:. So we see many problems here, not the least of which are frantic, screaming managers and sleepless DBAs. And this reinforces another famous saying: We also see how the effects of a bad design can spill over into the other departments in a company, raising costs and blood pressures and creating many fragile and unnecessary business processes to accommodate the bad design.
Surely there must be a better way. Now, let's see what happens if we break down, repent, and just accept the fact that these promotions live and die by dates. We would include 2 dates in the PromotedProducts table signifying the Start and End dates of the Promotion. The first thing we then notice is that these 2 new columns must be included in the Primary Key, since there can now be several promotions for the same product.
Here is the new database schema:. All we did was add the 2 dates in the PromotedProducts table, but the real magic is what the application does with this data: It would look in the PromotedProducts table using the effective dates to determine if the promotions are active and should be displayed. Using this design, let's look at the weaknesses of the previous design and see what's happened to them:.
This simple example illustrates how beneficial it is to consider including Effective Dates into your database schema. I have seen both of these scenarios at work and the difference is too vast to be ignored. You go from a frantic, stressful environment focused on how to make the systems work to a relaxed, confident environment focused on how to better run the business. And all because you let the software handle all the work. And isn't that what software is supposed to do in the first place? So that is the good news. In the next article of the series I will present the impact and pitfalls of the Effectively Dated design above and how to overcome them.
We will build on the simple data model that we started with here and see what issues surface as you take Effective Dating further and further. In the final step of Database Design, Joe Celko gives a simple but effective explanation of the norm Daily SQL Articles by email:. Stay up to date: Daily newsletters with brand new articles, scripts, editorials and a Question of the Day help you keep on top of SQL Server. What would you like to see in a dating site?
If you have any suggestions, please leave a comment below. Code is still very much in progress, but if you want to see what I have so far, take a sneak peak at this github repository.
The person who wrote the post chooses to initiate the conversation. If the conversation goes badly, the initiator can block the other person permanently.
Graph data can be complex to work with. And this reinforces another famous saying: However, as with many things, "the Devil is in the details", and in this case, it's a really big Devil: For this we will use a online dating example. Sometimes though, it is opposites that attract. Start doing it too!
You are commenting using your WordPress. You are commenting using your Twitter account. You are commenting using your Facebook account. Notify me of new comments via email. Max De Marzi Graphs with Neo4j. Home About Contact Services Videos. July 16, at Leave a Reply Cancel reply Enter your comment here Fill in your details below or click an icon to log in: Email required Address never made public.