Posts

Showing posts with the label DatabaseFiles

"The WITH MOVE clause can be used to relocate one or more files." Error while restore

Image
Recently trying to restore a database following message was thrown: System.Data.SqlClient.SqlError: File 'F:\DATA\DatabaseName.mdf' is claimed by 'DBFileGroup1'(3) and 'DBFile'(1). The WITH MOVE clause can be used to relocate one or more files. (Microsoft.SqlServer.Smo) The issue might be because of the restore process using same physical file name and path for two different database files. Go to the options tab and see. Following is the screenshot: In any file system there would be no physical files with same name in any given folder. This is why the error comes. Just modify the file name as per your requirement as below: Now hit the OK button. This will restore the database without any error.

Get disk space usage of database files

Sp_helpfile is an option to query the size of the database file but it does not give how much disk space out of the allocated is being used by the data or log file. Below is the query which can be used to fetch the details like disk space allocated to each data and log file for the database and how much is used and how much is free. It also gives the physical location of the files. USE DatabaseName; GO SELECT NAME AS LogicalFileName ,CAST(size / 128.0 AS DECIMAL(20, 2)) [Total(MB)] ,CAST(CAST(FILEPROPERTY(NAME, 'SpaceUsed') AS INT) / 128.0 AS DECIMAL(20, 2)) AS [Used(MB)] ,CAST((size - CAST(FILEPROPERTY(NAME, 'SpaceUsed') AS INT)) / 128.0 AS DECIMAL(20, 2)) [Remaining(MB)] ,physical_name AS Path FROM sys.database_files

Make Money from Surveys