如何修改SqlServer数据库的实际存储的名称?

2024-12-27 17:50:51
推荐回答(2个)
回答1:

--BACKUP
BACKUP DATABASE test TO DISK = 'G:\test.BAK'

--RESTORE
RESTORE DATABASE test1
FROM DISK='G:\test.BAK'
WITH MOVE 'test_data' TO 'G:\sqldata\test1_data.mdf',
MOVE 'test_log' TO 'L:\test1_log.ldf', REPLACE
GO
ALTER DATABASE test1
MODIFY FILE (NAME = 'test_data', NEWNAME = 'test1_data')
GO
ALTER DATABASE test1
MODIFY FILE (NAME = 'test_log', NEWNAME = 'test1_log')
GO

回答2:

RESTORE DATABASE Test1
FROM DISK = 'c:\TEST.bak'
WITH MOVE 'Test' TO 'c:\test\test1.mdf',
MOVE 'Test1_log' TO 'c:\test\test1.ldf'