1, DBCC PINTABLE
Marks a table to be pinned, which means Microsoft SQL Server does not flush the pages for the table from memory.
Syntax
DBCC PINTABLE ( database_id , table_id )
To determine the database ID, use the DB_ID function.
To determine the table ID, use the OBJECT_ID function.
注释
DBCC PINTABLE 不会导致将表读入到内存中。当表中的页由普通的 Transact-SQL 语句读入到高速缓存中时,这些页将标记为内存驻留页。当 SQL Server 需要空间以读入新页时,不会清空内存驻留页。SQL Server 仍然记录对页的更新,并且如有必要,将更新的页写回到磁盘。然而,在使用 DBCC UNPINTABLE 语句使该表不驻留之前,SQL Server 在高速缓存中一直保存可用页的复本。
示例:
Declare @db_id int, @tbl_id int
Use DATABASE_NAME
Set @db_id = DB_ID('DATABASE_NAME')
Set @tbl_id = Object_ID('Department')
DBCC pintable (@db_id, @tbl_id)
可将表Department设置为驻留内存。
Declare @db_id int, @tbl_id int
Use DATABASE_NAME
Set @db_id = DB_ID('DATABASE_NAME')
Set @tbl_id = Object_ID('Department')
DBCC UNpintable (@db_id, @tbl_id)
可将表Department取消设置为驻留内存。
2, SP_TableOption
Sets option values for user-defined tables. sp_tableoption may be used to turn on the text in row feature on tables with text, ntext, or image columns.
Syntax
sp_tableoption [ @TableNamePattern = ] 'table'
, [ @OptionName = ] 'option_name'
, [ @OptionValue = ] 'value'
其中,'option_name' 有如下用法:
pintable -- When disabled (the default), it marks the table as no longer RAM-resident. When enabled, marks the table as RAM-resident. (可将指定的表驻留内存)
另外,table lock on bulk load, insert row lock, text in row等等可选值,因不涉及将表驻留内存,具体用法可以查询SQL Server Books Online.
Value有如下用法:
the option_name is enabled (true, on, or 1) or disabled (false, off, or 0)
3. Conclusions
将数据表设置为驻留内存时,并没有实际将表读入内存中,直到该表从被检索。因此,可以使用如下SQL指令进一步将数据表Department驻留内存:
Select * From Department
另外,可以使用如下SQL指令方便显示/检测数据库Database中所有设置为驻留内存的表:
SELECT * FROM INFORMATION_SCHEMA.Tables
WHERE TABLE_TYPE = 'BASE TABLE'
AND OBJECTPROPERTY(object_id(TABLE_NAME), 'TableIsPinned') > 0