What i have is approximately 15 tables, each with about 10 columns and almost 1 million rows of data.
All the 15 tables have the same primary keys I can use to join them by.
For example..
Table 1 – Columns A B C D E
Table 2 – Columns A B F G H
Table 3 – Columns A B I J K
Table 4 – Columns A B L M N
etc.. where A & B are the primary keys
What I need would be one huge table that looks like this..
mainTable – Columns A B C D E F G … M N
Right now, what I have done is:
– Start off with Table 1 as my “main” table
– Alter the table to add all the columns.. (i.e. F G H .. L M N)
– use an UPDATE command to fill in the “main” table
update mainTable set
F = a.F,
G = a.G,
H = a.H
from mainTable left join Table2 a on
mainTable.A = a.A and
mainTable.B = a.B
(rinse and repeat for each of the 15 tables)
This seems to work, just that it’s horribly inefficient. It takes ages to join just one table..
Is there an alternative/faster method of performing this task?
Updates are often slower than inserts. Rather create a new table and insert all the data into it.