My brother made a smirk remark at me a little while ago. He said “You used this computer a lot and so how come @@servername is returning null“.
Servername is null
And, so I took the time to explain that @@servername is a bit legacy. And, that there are more modern ways to determine the server’s name.
Issuing serverproperty, which has been available since at least v2005 offers more flexibility and insight.
To fix his problem, we of course, can use the sp_addserver SP.
exec sp_addserver @server = [server] , @local = 'local'
exec sp_addserver @server = 'LABDB' , @local = 'local'
Please restart the SQL Instance for the change to effect.
Btw, if a wrong or an old computer name, had been returned we would of course have to disassociate using sp_dropserver.