DBCC CHECKDB-feilsøking av skadet SQL Server-database

Resumen: DBCC CHECKDB, DBCC, databasereparasjon, database, skadet 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 skadet og må repareres for å opprettholde stabilitet og konsistens.

Causa

Programvare som er skadet i MS SQL Server-database, logger og applikasjonsfiler.

Resolución

DBCC er et innebygd verktøy for Microsoft SQL Server som er utviklet for å kontrollere og reparere Microsoft SQL Server-databaser.  Denne artikkelen drøfter DBCC CHECKDB-kommandoen og -alternativene for å kontrollere logisk og fysisk integritet i databasen.

DBCC CHECKDB-informasjon

DBCC CHECKDB (Transact-SQL):

https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-checkdb-transact-sql?view=sql-server-ver15Denne hyperkoblingen tar deg til et nettsted utenfor Dell Technologies.

Fremgangsmåte for å kjøre DBCC CHECKDB:

  1. Åpne SQL Server Studio Management
  2. Åpne et spørringsvindu
  3. Skriv inn «DBCC CHECKDB (databasenavn)»

Resultater for DBCC CHECKDB kjøres
 

        4. Kontroller nederst i spørringsresultatene for å se feil med tildeling og konsistens. 
        5.  Hvis det vises tildelings- og konsistensfeil i resultatene, skal databasen enten gjenopprettes fra sikkerhetskopiering eller utføre en databasereparasjon ved hjelp av DBCC CHECKDB.          

Alternativer for DBCC-reparasjon

  1. REPAIR_REBUILD: Kommandoen nedenfor setter databasen i en modus som tillater reparasjon.
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 lim den inn i spørringsøkten med riktig 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: Kommandoen nedenfor utfører databasereparasjon og kan føre til tap av data for å fullføre reparasjonsprosessen.

--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 lim den inn i spørringsøkten med riktig databasenavn:

Kommandoene nedenfor er nyttige hvis det er lite fysisk diskplass i databasen.

--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 lim den inn i spørringsøkten med riktig 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 og lim inn spørringsøkten, og angi riktig 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

Informasjon om når du skal bruke 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.