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

Riepilogo: DBCC CHECKDB, DBCC, databasereparasjon, database, skadet database

Questo articolo si applica a Questo articolo non si applica a Questo articolo non è legato a un prodotto specifico. Non tutte le versioni del prodotto sono identificate in questo articolo.

Sintomi

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.

Risoluzione

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

Prodotti interessati

Dell Quickstart Data Warehouse Appliance, Prosupport for Microsoft Software
Proprietà dell'articolo
Numero articolo: 000134529
Tipo di articolo: Solution
Ultima modifica: 18 mar 2025
Versione:  5
Trova risposta alle tue domande dagli altri utenti Dell
Support Services
Verifica che il dispositivo sia coperto dai Servizi di supporto.