Query for repairing SQL Databases

Database needs to bring the database into single user  mode then only you can execute DBCC CHECKDB command, otherwise you will get errors. see the below example to bring database into single user mode.
Use database_name
GO
ALTER DATABASE database_name SET SINGLE_USER
GO
DBCC CHECKDB('database_name', REPAIR_REBUILD)
GO

  • to return to multi-user mode: 
ALTER <database-name> SET MULTI_USER

Reason for Execute the above Command in Single User Mode

it is required to run this command in SINGLE USER Mode. This is because when SQL does thie REPAIR_REBUILD command internally it allocate/deallocate references to the pages and move them here and there. So that is the reason for running this command in SINGLE USER mode.