Home > Blockchain >  How can i import millions of records from client database into mine in less time
How can i import millions of records from client database into mine in less time

Time:10-08

SELECT * 
FROM dbo.STSQ01
WHERE BegSchSessYr BETWEEN YEAR(GETDATE())-3 AND YEAR(GETDATE())-1

This is my query to pull the 3 last years of data from clients database and the records are millions and it is taking a lot of times to fetch the data. how can i make my query run more quick. Please help. Thanks

CodePudding user response:

you need an index on BegSchSessYr column if you don't have already:

create index on STSQ01 (BegSchSessYr)

also only select columns that you want

CodePudding user response:

Write a script in whatever programming language that runs it in chunks using LIMIT clause. So you only grab like 50,000 records at a time. Should speed things up.

  •  Tags:  
  • sql
  • Related