devxlogo

Employing DBCC PINTABLE and DBCC UNPINTABLE Functions

SQL Server automatically loads the data it needs to work with into its cache. This is called pages. These data pages stay in SQL Server’s cache until there is no room for them and it gets flushed out of the data cache onto disk.

Whenever SQL Server needs these data pages again, it must to go to disk and read them into the cache again. To ensure a table always stays available in SQL Server’s cache you could Pin the table and Unpin it when it is not needed anymore. For this you make use of the DBCC PINTABLE and DBCC UNPINTABLE Functions. Here is a very small example:

Pinning

DECLARE @DatabaseID INT, @TableID INTUSE DatabaseName SET @DatabaseID = DB_ID('DatabaseName') SET @TableID = OBJECT_ID('TableName') DBCC PINTABLE (@DatabaseID, @TableID) 

Unpinning

DECLARE @DatabaseID INT, @TableID INT USE DatabaseName SET @DatabaseID = DB_ID('DatabaseName') SET @TableID = OBJECT_ID('TableName') DBCC UNPINTABLE (@DatabaseID, @TableID) 

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.