DBCC CHECKDB- fejlfinding af beskadigelse af SQL Server-database

Resumen: DBCC CHECKDB, DBCC, databasereparation, database, beskadiget database

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 er beskadiget og skal repareres for at opretholde stabilitet og konsistens.

Causa

Softwarefejl i MS SQL Server-database, logfiler og programfiler.

Resolución

DBCC er et indbygget værktøj i Microsoft SQL Server, der er designet til at kontrollere og reparere Microsoft SQL Server-databaser.  Denne artikel beskriver kommandoen og indstillingerne for DBCC CHECKDB i kontrol af databasens logiske og fysiske integritet.

DBCC CHECKDB-oplysninger

DBCC CHECKDB (Transact-SQL):

https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-checkdb-transact-sql?view=sql-server-ver15Dette hyperlink fører dig til et websted uden for Dell Technologies.

Trin til at køre DBCC CHECKDB:

  1. Open SQL Server Studio Management
  2. Åbn et forespørgselsvindue
  3. Indtast "DBCC CHECKDB (Databasenavn)"

Resultater for kørsel af DBCC CHECKDB
 

        4. Kontroller nederst i forespørgselsresultaterne for at se allokerings- og konsistensfejl. 
        5.  Hvis der vises allokerings- og konsistensfejl i resultaterne, skal databasen enten gendannes fra en sikkerhedskopi eller udføres en databasereparation vha. DBCC CHECKDB.          

DBCC-reparationsindstillinger

  1. REPAIR_REBUILD: Kommandoen nedenfor sætter databasen i en tilstand, der tillader 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

Kopier kommandoen nedenfor, og indsæt den i forespørgselssessionen med det korrekte databasenavn:

--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: Nedenstående kommando udfører databasereparation og kan resultere i tab af data for at fuldføre 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

Kopier kommandoen nedenfor, og indsæt den i forespørgselssessionen med det korrekte databasenavn:

Nedenstående kommandoer er nyttige, hvis databasens fysiske diskplads er ved at løbe tør for plads.

--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

Kopier kommandoen nedenfor, og indsæt den i forespørgselssessionen med det korrekte databasenavn:

--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

Kopier kommandoen nedenfor, indsæt til forespørgselssessionen, og indsæt det korrekte databasenavn:

--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

Oplysninger om, hvornår du skal bruge 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.