使用备份文件指定新的数据库名称
USE MASTER
RESTORE DATABASE [tsw_test]
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup\Tsw.bak'
WITHMOVE 'tsw_test' TO 'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\tsw_test.mdf', MOVE 'tsw_test_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\tsw_test_log.ldf',
STATS = 10, REPLACE
GO
使用备份文件还原原本的
ALTER DATABASE [test] SET OFFLINE WITH ROLLBACK IMMEDIATE USE MASTER
RESTORE DATABASE [test]
FROM DISK = 'C:\Users\xxx\Desktop\exxx_zy.bak'
WITHMOVE 'exxx_zy' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\exxx_zy.mdf', MOVE 'exxx_zy_LOG' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\exxx_zy.ldf',
STATS = 10, REPLACE
GOALTER database [test] set online