I have a very big table with 20 million records DistinctProjectionKey
which i join several times to different tables in this query.
select distinct distinctprojectionkeyid,dpk.MarketID,
dpk.Classificationid,
dpk.DistributorID,
dpk.ManufacturerID,
dpk.LocationID,
dpk.TimeID,P4.FACTOR as factor1,P3.FACTOR as factor2 ,P2.FACTOR as
factor3,P1.FACTOR as factor4
into Projectionfactors1
FROM DistinctProjectionKey dpk INNER JOIN D_Time t
ON t.TimeID = dpk.TimeID
INNER JOIN (select * from (select distinct
ClassificationID_Major,'fam' as lab from
StagingOLTP..ClassificationFlat) cf1)cf
ON cf.ClassificationID_Major = dpk.ClassificationID
LEFT OUTER JOIN StagingOLTP..ProjectionDefaultFlat p4
ON t.TheDate = p4.TheDate
AND p4.Name = 'FAM'
AND cast(cf.Lab as varchar(20)) = cast(p4.Lab as varchar(20))
AND dpk.MarketID = p4.MarketID
AND p4.ManufacturerID IS NULL
AND p4.ClassificationID IS NULL
LEFT OUTER JOIN StagingOLTP..ProjectionDefaultFlat p3
ON t.TheDate = p3.TheDate
AND p3.Name = 'fam'
AND cast(cf.Lab as varchar(20)) = cast(p3.Lab as varchar(20))
AND dpk.MarketID = p3.MarketID
AND p3.ClassificationID = dpk.ClassificationID
AND p3.ManufacturerID IS NULL
LEFT OUTER JOIN StagingOLTP..ProjectionDefaultFlat p2
ON t.TheDate = p2.TheDate
AND p2.Name = 'fam'
AND cast(cf.Lab as varchar(20)) = cast(p2.Lab as varchar(20))
AND dpk.MarketID = p2.MarketID
AND p2.ManufacturerID = dpk.ManufacturerID
AND p2.ClassificationID IS NULL
LEFT OUTER JOIN StagingOLTP..ProjectionDefaultFlat p1
ON t.TheDate = p1.TheDate
AND p1.Name = 'fam'
AND cast(cf.Lab as varchar(20)) = cast(p1.Lab as varchar(20))
AND dpk.MarketID = p1.MarketID
AND p1.ManufacturerID = dpk.ManufacturerID
AND p1.ClassificationID = dpk.ClassificationID
the other table have fewer number of records .
I find that when I try to do the insert tempdb goes out of control ,it
grows above 100 GB?
Would anyone know the reason why and the solution to apply to avoid
this problem?
The other tables have fewer recods
Classification flat has 5000 records and projection default flat has
32652 records.
Ajay
Ajay