1.sql server 2008
USE master
ALTER DATABASE [KH2020] SET OFFLINE WITH ROLLBACK IMMEDIATE
RESTORE database [KH2020] from disk='D:\客户数据\HHerp_lgyy202108231053\HHerp_lgyy202108231053.bak' with RECOVERY,REPLACE
ALTER database [KH2020] set online
USE KH2020
UPDATE dbo.loginuser SET password=''
2.sql server 2016
USE master
DECLARE @spid INT
DECLARE getspid CURSOR
FOR
SELECT spid
FROM sysprocesses
WHERE dbid = DB_ID('CustomData')
OPEN getspid
FETCH NEXT FROM getspid INTO @spid
WHILE @@fetch_status <> -1
BEGIN
EXEC('kill '+ @spid)
FETCH NEXT FROM getspid INTO @spid
END
CLOSE getspid
DEALLOCATE getspid
ALTER DATABASE TTTTT SET OFFLINE WITH ROLLBACK IMMEDIATE
RESTORE DATABASE TTTTT FROM DISK='D:\服务器\Program\CarpaServer\backup\FZYUN388768.bak'WITH REPLACE
ALTER database TTTTT set online
USE TTTTT