Skip to content

Instantly share code, notes, and snippets.

@lee-pai-long
Last active January 20, 2016 17:55
Show Gist options
  • Save lee-pai-long/4030ae2c1c4448d0d829 to your computer and use it in GitHub Desktop.
Save lee-pai-long/4030ae2c1c4448d0d829 to your computer and use it in GitHub Desktop.

[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>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment