We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


DeNormalise data - easy?!

niico asked
Medium Priority
Last Modified: 2012-06-27
I have an old database, currently it stores customer data (along with contact details) and in a related table (on customersID) stores alternate contact information (name, phone email). There are usually 0-3 of these alternate contacts for each customer, though sometimes there are more.

In my new system direct in the customers table there is space for three alternate contacts, which can be filled in or left blank as required. How can I transfer the old format all into one customers table that includes room for the alt contacts - in other words denormalise the data (in a way anyway). Remembering that current customers may have no alternate contacts or over three (in which case the 4th, 5th etc are just disguarded).

Watch Question

Top Expert 2011

I could ask why denormalise...?


insert into newcustomer
  (column list)
 Select column List
  From OldCustomer as O
  Left Outer Join AltContact as A
   on O.CustomerID = A.CustomerID
 Left Outer Join    AltContact as A1
   on O.CustomerID = A1.CustomerID
 and A1.Name > A.Name
 Left Outer Join    AltContact as A2
   on O.CustomerID = A2.CustomerID
 and A2.Name > A1.Name

should do it...



Im denormalising basically because the customers table is queried thousands of times a day - to pull records from two tables will hit performance, and complicate things a lot more than pulling from one no?

ok ill give it a go!...
Top Expert 2011

not necessarily

its a trade off, you've just made the customer row much bigger than necessary , and subject to more update activity
which means less efficient I/O overrall...

how often does the contact information need to be referenced when you reference the customer?

how was the contact information clustered?
a half way house would be to hold an indicator on customer to say that contact information was actually present
or implement the customer / contact information as a view (like my select)

do you perform name searches against this customer table?
  if you do I'd expect performance to markedly decrease (depending on your server configuration)

did you do any performance analysis before you considered this route?



in this case it 'felt' like the right thing to do. Everytime the customer record is accessed there will need to be a scan to at least check if alternate contacts exist (your indicator is a good idea but adds even more complexity). Then if they are added or updated it adds to the complexity of the update a lot as well.

It speeds development and simplifies updates. Also we've decided that three alternates is all that's necessary - if we go the normalised route there could be 0-any number of alternatives (though we could artificially limit this)> this requires additional interface complexity etc - same with updating.

ultimately a select with a join will be slower than a select with no join (if the combined row size is the same) - no?

Yes like you say there is a downside with larger row - but overall it makes things a lot easier (performance hasn't been a problem - like you say some analysis would be the absolute best route but in this case is probably not necessary).

Thanks for views - I'll get back to you on the solution.


its working but creating a new row for each alternate customer id and putting all id's in the a1name column - any ideas? thanks...
Top Expert 2011
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview


hi - thanks again

There is a key on the alt contacts table (altid, int) (if not I could add one)> is the above code for without a key?

would a cursor be easier for this? As its code I only need to run once then its done?...


also - out of interest, the (column list) select column List - parts of the sql didnt work, I had to remove them to execute the code. This is sql2k sql isnt it?


thanks for the input - you seemed to be on the right track. As it was a one off job and I needed it to be done fast I just used a cursor in the end and its worked - thanks again though.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.