Recently, I wanted to resize the tempdb file size to 2 MB so I ran the below script:
ALTER DATABASE tempdb MODIFY FILE (name = tempdb, size = 2MB);
and got the below error:
Msg 5041, Level 16, State 2, Line 1
MODIFY FILE failed. File ‘tempdb’ does not exist. (screenshot below)
After some research I found out that the file name that I was using was incorrect. To find the correct logical name, you have to right-click the database, go to Properties —> Files and you’ll see it under Logical Name (see green arrow in screenshot image below). In my case it was “tempdev” NOT “tempdb” (which is what I used and got the error).
Once I put that name in the script it ran perfectly fine. Make sure to restart SQL Service in order to see the change.
ALTER DATABASE tempdb MODIFY FILE (name = tempdev, size = 2MB);