If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Patterns for things that change with time

Closed Thread
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-05-07, 05:04
Liuk Liuk is offline
Registered User
 
Join Date: Feb 2007
Posts: 11
Patterns for things that change with time

Hi
i have an table where i store addresses of my contact. A contact may change address and i want to keep track of these changes in order to be able,for example, to determine what address a contact had on a certain data. Is there some pattern describing this kind of temporal issue?
thanks
  #2 (permalink)  
Old 06-05-07, 05:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
i'm not sure what a pattern is, but one common way of doing what you ask is to have two additional datetime columns in the table, effective_from and effective_to

effective_to would be set to NULL for the current address

when the contact changes, set effective_to to the change datetime, and insert a new row with the change datetime as effective_from and NULL as effective_to

to find the current address, just use
Code:
... WHERE effective_to is null
to find the address at any time in the past, use
Code:
... WHERE '2002-11-15' between effective_from and effective_to
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
  #3 (permalink)  
Old 06-05-07, 06:03
Liuk Liuk is offline
Registered User
 
Join Date: Feb 2007
Posts: 11
thank you very much.
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On