Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Apr 26, 2000

Data Warehouse Version Management

By Les Smith

In most tables it is enough to have a stored procedure that performs Update Else Insert logic for data managment. However, in some cases we do not want to destroy the old data with an update statement. Instead we want to maintain history up to a certain number of versions. For example a bank may wish to keep records of a customer's address changes. Another classic example mentioned by most data warehouse writers is a name change. A woman gets married and changes her name, but we wish to keep a record of both the current name and the historical name.

We can track this information by having a main ID (an integer) in the table and then another ID for tracking changes (a decimal). In my example we have the integer field, CompanyID and then the dwCompanyID, a decimal. We version from n.10 to n.90. So nine versions of the CompanyID are allowed.

Our example is of a business that needs to track CreditStatus history for the last nine changes.The last version number must always be the most current.

If the CompanyID already has nine records in it the oldest record (CompanyID.10) is dropped, and then all the remaining records (.20 through .90) are decremented by one. Thus we can insert our record and it becomes the ninth version (CompanyID.90).

We also need to check if this is a valid version change. We need to check if the value in the CreditStatus field is actually different from the value held by the latest version. Otherwise we would see a history of a version change even if nothing had changed.

Thus suppose we enter a CreditStatus of 1 for Company 1. First parameter is CompanyID, second is CreditStatus. sp_slowChangeDim 1,1 The table will now look like this.

CompanyID dwCompanyID CreditStatus Date
1 1.10 1 Apr 25 2000 12:21PM

If we entered sp_slowChangeDim 1,1 another time there would be no changes. However, if we change the CreditStatus to 2 using "sp_slowChangeDim 1, 2" we would get a valid new version created.

CompanyID dwCompanyID CreditStatus Date
1 1.10 1 Apr 25 2000 12:21PM
1 1.20 2 Apr 25 2000 12:23PM

Download:



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM


















Thanks for your registration, follow us on our social networks to keep up-to-date