DBCC CHECKDB Felsökning av SQL Server-databasfel

Summary: DBCC CHECKDB, DBCC, databasreparation, databas, skadad databas

This article applies to This article does not apply to This article is not tied to any specific product. Not all product versions are identified in this article.

Symptoms

Problem: MS SQL Server-databasen är skadad och måste repareras för att bibehålla stabilitet och enhetlighet.

Cause

Skadad programvara i MS SQL Server-databasen, loggar och programfiler.

Resolution

DBCC är ett inbyggt verktyg i Microsoft SQL Server som är utformat för att kontrollera och reparera Microsoft SQL Server-databaser.  I den här artikeln beskrivs kommando och alternativ för DBCC CHECKDB vid kontroll av databasens logiska och fysiska integritet.

CHECKDB-information om DBCC

DBCC CHECKDB (Transact SQL):

https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-checkdb-transact-sql?view=sql-server-ver15Den här hyperlänken tar dig till en webbplats utanför Dell Technologies.

Steg för att köra CHECKDB för DBCC:

  1. Öppna SQL Server Studio Management
  2. Öppna ett frågefönster
  3. Skriv "DBCC CHECKDB (database name)"

Resultat för DBCC CHECKDB kör
 

        4. Kontrollera längst ned i frågeresultaten för att se allokerings- och konsekvensfel. 
        5.  Om allokerings- och konsekvensfel visas i resultaten bör databasen antingen återställas från säkerhetskopian eller utföra en databasreparation med hjälp av DBCC CHECKDB.          

Reparationsalternativ för DBCC

  1. REPAIR_REBUILD: Kommandot nedan försätter databasen i ett läge som möjliggör reparation.
USE Master;
GO
ALTER DATABASE TSQL2012
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
DBCC CHECKDB (TSQL2012, REPAIR_REBUILD)
GO
ALTER DATABASE TSQL2012
SET MULTI_USER;
GO

Kopiera kommandot nedan och klistra in i frågesessionen med rätt databasnamn:

--Command below performs a Database repair not allowing Data loss

USE Master;
GO
ALTER DATABASE TSQL2012
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
DBCC CHECKDB (TSQL2012,REPAIR_REBUILD)
GO
ALTER DATABASE TSQL2012
SET MULTI_USER;
GO

       2. REPAIR_ALLOW_DATA_LOSS: Kommandot nedan utför databasreparation och kan resultera i dataförlust för att slutföra reparationsprocessen.

--Command below performs a database repair that may result in data loss,
 --replace TSQL2012 with the database name of database being repaired
USE Master
GO
ALTER DATABASE TSQL2012
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE
GO
DBCC CHECKDB (TSQL2012, REPAIR_ALLOW_DATA_LOSS)
GO
ALTERDATABASE TSQL2012
SET MULTI_USER
GO

Kopiera kommandot nedan och klistra in i frågesessionen med rätt databasnamn:

Kommandona nedan är användbara om databasens fysiska diskutrymme börjar ta slut.

--Command below estimates the size TEMPDB must be to complete the DBCC CHECKDB job
USE Master;
GO
ALTER DATABASE TSQL2012
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
DBCC CHECKDB (TSQL2012, REPAIR_REBUILD)
WITH ESTIMATEONLY;
GO
ALTER DATABASE TSQL2012
SET MULTI_USER
GO

Kopiera kommandot nedan och klistra in i frågesessionen med rätt databasnamn:

--Command below estimates the size TEMPDB must be to complete the DBCC CHECKDB job

USE Master;
GO
ALTER DATABASE TSQL2012
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
DBCC CHECKDB (TSQL2012, REPAIR_REBUILD)
WITH ESTIMATEONLY;
GO
ALTER DATABASE TSQL2012
SET MULTI_USER
GO

 

--Command below will run DBCC CHECKDB without using TEMDB and creating a DB 
--snapshot. When not using TEMPDB with a DB snapshot all data will be checked in
-- the live database not not a database snapshot.

USE Master;
GO
ALTER DATABASE TSQL2012
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
DBCC CHECKDB (TSQL2012, REPAIR_REBUILD)
WITH TABLOCK;
GO
ALTER DATABASE TSQL2012
SET MULTI_USER
GO

Kopiera kommandot nedan och klistra in i frågesessionen och ange rätt databasnamn:

--Command below will run DBCC CHECKDB without using TEMPDB and creating a DB 
--snapshot. When not using TEMPDB with a DB snapshot all data will be checked in ---the live database not a database snapshot.

USE Master;
GO
ALTER DATABASE TSQL2012
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
DBCC CHECKDB (TSQL2012, REPAIR_REBUILD)
WITH TABLOCK;
GO
ALTER DATABASE TSQL2012
SET MULTI_USER
GO

Information om när du ska använda DBCC CHECKDB

Affected Products

Dell Quickstart Data Warehouse Appliance, Prosupport for Microsoft Software
Article Properties
Article Number: 000134529
Article Type: Solution
Last Modified: 18 Mar 2025
Version:  5
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.