I think I have a basic question here that many might have encountered. When I run a query in SQL Server it will load in memory all the data it needs for query execution (for
Old question, but figured i'd add my two cents. Mostly a riff on what was in the above answer using dsql to automatically roll back to the previous value after shrinking the memory amount. It's ugly, but it works.
IF OBJECT_ID(N'tempdb..##globaltemp') IS NOT NULL
BEGIN
DROP TABLE ##globaltemp
END
SELECT TOP 1 value
INTO ##globaltemp
FROM sys.configurations
WHERE NAME LIKE '%server memory%'
ORDER BY NAME
OPTION (RECOMPILE);
EXEC sys.sp_configure N'max server memory (MB)'
, N'1024'
GO
RECONFIGURE
WITH OVERRIDE
GO
DECLARE @dsql AS VARCHAR(20)
SELECT @dsql = cast(value AS NVARCHAR(20))
FROM ##globaltemp
EXEC sys.sp_configure N'max server memory (MB)'
, @dsql
GO
RECONFIGURE
WITH OVERRIDE
GO