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

Summary: DBCC CHECKDB, DBCC, databasereparasjon, database, skadet database

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 er skadet og må repareres for å opprettholde stabilitet og konsistens.

Cause

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

Resolution

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

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.