On my machine select @@SERVERNAME was returning “Windows7” instead of the actual server name.
I wanted to use @@ServerName for some script validation and hence needed it to return the correct machine name.
Here is what I had to do:
EXEC Sp_dropserver 'Windows7'
EXEC Sp_dropserver 'machineName' –this is not necessary, but on my machine I had a weird conflict and hence had to do it
EXEC Sp_addserver 'machineName', 'local' –the local argument is REQUIRED
Finally restart your SqlServer instance.
Now run the following command to make sure everything worked correctly.
SELECT @@SERVERNAME AS SqlServerThinksTheServerIs, Serverproperty('Servername') AS theActualServerNameIs
The @@ServerName is especially important for the database deployment scripts created by Visual Studio’s database project as it uses it to validate that the script is being run on the correct machine.