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

Résumé: DBCC CHECKDB, DBCC, databasereparasjon, database, skadet database

Cet article concerne Cet article ne concerne pas Cet article n’est associé à aucun produit spécifique. Toutes les versions du produit ne sont pas identifiées dans cet article.

Symptômes

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.

Résolution

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

Produits concernés

Dell Quickstart Data Warehouse Appliance, Prosupport for Microsoft Software
Propriétés de l’article
Numéro d’article: 000134529
Type d’article: Solution
Dernière modification: 18 Mar 2025
Version:  5
Trouvez des réponses à vos questions auprès d’autres utilisateurs Dell
Services de support
Vérifiez si votre appareil est couvert par les services de support.