I have created this query to partition 10 million records into tables of 500k records each.
DECLARE @PageNumber AS INT
DECLARE @RowsOfPage AS INT
DECLARE @MaxTablePage AS FLOAT
SET @PageNumber=1
SET @RowsOfPage=500000
SELECT @MaxTablePage = COUNT(*)
FROM [dbo].[50m_rows]
where [Order Date] between '04/06/2020 12:00:00' and '10/05/2020 23:59:59'
SET @MaxTablePage = CEILING(@MaxTablePage/@RowsOfPage)
WHILE @MaxTablePage >= @PageNumber
BEGIN
SELECT *
FROM [dbo].[50m_rows]
where [Order Date] between '04/06/2020 12:00:00' and '10/05/2020 23:59:59'
ORDER BY [Order Date]
OFFSET (@PageNumber-1)*@RowsOfPage ROWS
FETCH NEXT @RowsOfPage ROWS ONLY
SET @PageNumber = @PageNumber 1
END
Please let me know if you have any trouble with that.
CodePudding user response:
I hope your table is indexed. If it is not, please apply an index. Then, try to do the export in chunks, like this.
SELECT [URL]
FROM [dbo].[siteentry]
WHERE [Content] LIKE ''
ORDER BY (some column)
OFFSET 20000 ROWS
FETCH NEXT 20000 ROWS ONLY
You have to order by some column, or the results will be essentially arbitrary.
See the link below for more info.