/* 规则 如果16G及以下,给2G给操作系统 如果32G及以下,给4G给操作系统 如果32G以上(不含32G),给内存的10%给系统*/use mastergodeclare @physical_memory intdeclare @TempTable table([Index] VARCHAR(2000) ,[Name] VARCHAR(2000) ,[Internal_Value] VARCHAR(2000) ,[Character_Value] VARCHAR(2000));INSERT INTO @TempTableEXEC xp_msver;SELECT @physical_memory=cast(Internal_Value as int)FROM @TempTableWHERE Name = 'PhysicalMemory';print @physical_memoryif @physical_memory<=1024*16 set @physical_memory=@physical_memory-1024*2else if @physical_memory<=1024*32 set @physical_memory=@physical_memory-1024*4 else set @physical_memory=@physical_memory*0.9print @physical_memoryEXEC sys.sp_configure N'max server memory (MB)',@physical_memoryGORECONFIGURE WITH OVERRIDEGO