SQL Backup creates a file which you can direct to a location and to which you can provide a name.
BACKUP DATABASE [AdventureWorks] TO DISK = 'c:\mssql\backup\yukon\AW2K5_Full.bak'
WITH CHECKSUM, COPY_ONLY, FORMAT, INIT, STATS = 10;
In this example, the database is changed to single-user mode and dropped. The mdf and ldf files remain in place. A backup is done AFTER the file is dropped. The contents of the .bak file can be displayed with
RESTORE FILELISTONLY FROM DISK = 'c:\mssql\backup\yukon\AW2K5_Full.bak' -- WITH FILE = 1
which will return the logicalName, physicalName, type (D vs L), filegroup name, size, FileID.
Another approach is
RESTORE VERIFYONLY FROM DISK = 'c:\mssql\backup\yukon\AW2K5_Full.bak'
also review the current physical location of the mdf and ldf files with t-sql tosys.master_files
, [type_desc] [file_type]
, [name] [logical_name]
WHERE [database_id] IN (DB_ID('AdventureWorks'))
ORDER BY [type], DB_NAME([database_id]);
If we restore now even to a new name, the data and log files in the .bak file are in the default locations and we will get rrros including the suggestion to use move.
The restore plan below changes the name from AdventureWorks to AdventureWorksCopy from the AdventureWorks full backup .bak file, and moved data and log from the default location to a new location.
RESTORE DATABASE [AdventureWorksCopy] FROM DISK = 'c:\mssql\backup\yukon\AW2K5_Full.bak'
MOVE 'AdventureWorks_Data' TO 'c:\mssql\data\yukon\AdventureWorksCopy_Data.mdf',
MOVE 'AdventureWorks_Log' TO 'c:\mssql\log\yukon\AdventureWorksCopy_Log.ldf',
RECOVERY, REPLACE, STATS = 10;