lee-pai-long
1/20/2016 - 2:24 PM

verify-database-integrity_sqlserver.md

[SQLSERVER] Verify database integrity

Connect to SQLSERVER

> osql -S <SERVER>/<INSTANCE> -E

Check integrity

> DBCC CHECKDB('<db_name>') WITH NO_INFOMSGS

if it doesn't return a message it means that the database is ok

Otherwise it will return one of the two following repair level:

- REPAIR_ALLOW_DATA_LOSS
- REPAIR_REBUILD

Activate single user mode

> exec sp_dboption '<db_name>','single user','<true>';

Repair database

> DBCC CHECKDB('<db_name>','<repair_level>')

Stop single user mode

> exec sp_dboption '<db_name>','single user','<false>';