Tuesday, 7 February 2023

DBCC CHECKDB & DBCC CHECKTABLE

 DBCC CHECKDB & DBCC CHECKTABLE

 

Examples

A. Check a specific table

The following example checks the data page integrity of the HumanResources.Employee table in the AdventureWorks2019 database.

SQL
DBCC CHECKTABLE ('HumanResources.Employee');
GO

B. Perform a low-overhead check of the table

The following example performs a low overhead check of the Employee table in the AdventureWorks2019 database.

SQL
DBCC CHECKTABLE ('HumanResources.Employee') WITH PHYSICAL_ONLY;
GO

C. Check a specific index

The following example checks a specific index, obtained by accessing sys.indexes.

SQL
DECLARE @indid int;
SET @indid = (SELECT index_id
              FROM sys.indexes
              WHERE object_id = OBJECT_ID('Production.Product')
                    AND name = 'AK_Product_Name');
DBCC CHECKTABLE ('Production.Product',@indid);  

Examples

A. Check both the current and another database

The following example executes DBCC CHECKDB for the current database and for the AdventureWorks2019 database.

SQL
-- Check the current database. DBCC CHECKDB; GO -- Check the AdventureWorks2019 database without nonclustered indexes. DBCC CHECKDB (AdventureWorks2019, NOINDEX); GO

B. Check the current database, suppressing informational messages

The following example checks the current database and suppresses all informational messages.

SQL
DBCC CHECKDB WITH NO_INFOMSGS; GO
 

 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Blog Archive