One of the most popular questions I often receive is why do I like to do consultation – my answer is very simple – it gives me an opportunity to learn continuously learn new things from my clients. Here is a script which I have built during my recent Comprehensive Database Performance Health Check. To perform one of the performance tuning tasks we needed a list of all the logical and physical names for the files for every single database on the SQL Server Instance. Here is the script which can list all the physical and logical name of the files along with their type as well.
SELECT d.name DatabaseName, f.name LogicalName, f.physical_name AS PhysicalName, f.type_desc TypeofFile FROM sys.master_files f INNER JOIN sys.databases d ON d.database_id = f.database_id GO
You can see the result of the script here.
In the result set, you can see database name, logical file name, physical file name, and type of the file.
The reason, I decided to blog about this script because even though it is a very simple script I was particular, not able to find such script online. I believe sometimes we skip learning a simple script and write a complicated script.
If you have any similar script which is simple and you use daily, please send them to me. I will blog them with the due credit to you.
Reference: Pinal Dave (https://blog.sqlauthority.com)