日期:2014-05-17  浏览次数:20397 次

帮忙解决下
我在用SQL2008试用版做一个模拟,计算机内存8G。数据库中有一个表只读不用写,为了提高运行速度,想把这个表驻留在内存里,运行相关代码后,显示执行成功,可经检测返回值为0.就是说并没有驻留,原因找了很久也没有找到,还望各位给指点一二。

------解决方案--------------------
上面那个 dbcc pintable(数据库id,对象id) 在2008的语法是可以用的,但是没有用,不会对服务一有影响,也就是不会起作用。


if OBJECT_ID('a') is not null
   drop table a
go

--1.新建一个表
select * into a
from sys.objects


--2.查询表
select * from a


--3.能查询,是否缓存在内存中了
select db_name(database_id),
       file_id,
       page_id,
       page_type,
       is_modified,       
       o.name as table_name      
       
from sys.dm_os_buffer_descriptors d
inner join sys.allocation_units au
        on au.allocation_unit_id = d.allocation_unit_id
inner join sys.partitions p
        on au.container_id = p.hobt_id
inner join sys.objects o
        on p.object_id = p.object_id
where o.type_desc = 'USER_TABLE'
      and o.is_ms_shipped = 0
      and d.database_id = 数据库id
order by page_id