DBCC CHECKDB Felsökning av SQL Server-databasfel

Resumen: DBCC CHECKDB, DBCC, databasreparation, databas, skadad databas

Este artículo se aplica a Este artículo no se aplica a Este artículo no está vinculado a ningún producto específico. No se identifican todas las versiones del producto en este artículo.

Síntomas

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

Causa

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

Resolución

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

Productos afectados

Dell Quickstart Data Warehouse Appliance, Prosupport for Microsoft Software
Propiedades del artículo
Número del artículo: 000134529
Tipo de artículo: Solution
Última modificación: 18 mar 2025
Versión:  5
Encuentre respuestas a sus preguntas de otros usuarios de Dell
Servicios de soporte
Compruebe si el dispositivo está cubierto por los servicios de soporte.