-- Switch to master to avoid locking the target database
USE master;
GO

-- Set the target database to SINGLE_USER mode and force disconnects
ALTER DATABASE family
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO

-- Optional: Set it back to MULTI_USER mode after maintenance
-- ALTER DATABASE family
-- SET MULTI_USER;
-- GO
