You can do ALTER DATABASE <mydb> SET READ_ONLY to put the database in read-only mode.
If you want a command to fail if it cannot be executed immediately, you specify it as follows:
ALTER DATABASE <mydb> SET READ_ONLY WITH NO_WAIT
If you want to disconnect all open connections, you specify the command as follows:
ALTER DATABASE <mydb> SET READ_ONLY WITH ROLLBACK IMMEDIATE
These options are well described in SQL Server Online documentation.
source share