In Oracle database, place the instance in restricted mode. The users already connected to the database will not get disconnected. You need to manually kill these sessions.
SQL> alter system enable restricted session;
OR
Startup in restricted mode.
SQL> startup restrict;
Check the instance mode
SQL> select logins from v$instance;
LOGINS
----------
RESTRICTED
In SQL database, Below are the two most popular ways to set up database to single-user mode in SQL Server:
Using SQL Server Management Studio
Right-click the database to change, and then click Properties -> click the Options page->From the Restrict Access option, select Single.
If other users are connected to the database, an Open Connections message will appear. To change the property and close all other connections, click Yes.
Using Transact-SQL
USE master;
GO
ALTER DATABASE MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
Check SQL Database Single User or Multi User Mode
a) Select ServerProperty(‘IsSingleUser’)
It should return 1, 0, or Null.
1 = Single user.
0 = Not single user
NULL = Input is not valid, or an error.
use MyDatabase
go
Select ServerProperty('IsSingleUser')
b) Select from sys.database, it should retuen:
SELECT user_access_desc
FROM sys.databases
WHERE name = 'MyDatabase'
3) From SSMS, Right-click the database , and then click Properties -> click the Options page->From the Restrict Access option.