• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

@@servername - where does instance get that info

is it the 'computer name' of the SQL Server? or how/where does it get that info from?

thanks
0
anushahanna
Asked:
anushahanna
  • 3
  • 3
  • 2
  • +4
8 Solutions
 
mcv22Commented:
Its the local server name (initialized to computer name during setup). To change the name of the server, use sp_addserver, and then restart SQL Server. For the default instance its usually the computer name. For the named instance its computername\instancename.

The servername can be changed using sp_addserver and sp_dropserver procedures.
0
 
cyberkiwiCommented:
This looks like a definition question, the only best answer would be from the book itself...
http://msdn.microsoft.com/en-us/library/ms187944.aspx

@@servername reports from master..sysservers or sys.servers and is affected by sp_addserver, sp_dropserver

select SERVERPROPERTY('SERVERNAME')

SERVERPROPERTY / SERVERNAME returns the actual network name of the server
0
 
dqmqCommented:
It's the name that the computer running SQL Server is known by the network.  Usually the same as the name of the computer, but you can name it otherwise.  
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
sammySeltzerCommented:
During SQL Server setup, the computer or servername is setup at that time.


To get the servername where your sql server is set up, simply run:

SELECT @@SERVERNAME AS 'Server Name'

If for some reason you wish to change server name, you use this syntax:

 sp_addserver @server or

 sp_addserver 'servername'

You run this within sql query window

Hope this answers your question.
0
 
rajeshprasathCommented:
while installing the SQL Server it automatically takes the host name as @@SERVERNAME, But if you change the host name of the computer after installation. It won't change automatically.

The @@SERVERNAME remains the old host name. So at that time if you want to change the @@SERVERNAME you can do it by the following syntax,

sp_addserver 'new server name'

So it defines the name of the local instance of SQL Server.

you can also refer the following url,
http://msdn.microsoft.com/en-us/library/aa933172%28SQL.80%29.aspx
http://technet.microsoft.com/en-us/library/ms174411%28SQL.90%29.aspx
0
 
NormanMainaCommented:
select @@servername  for the default instance returns the server name while for named instances, it returns the computername\instancename.
That info is stored in the master table during install of the instances.
0
 
anushahannaAuthor Commented:
Thanks for your helpful input.

@@servername is not bringing the name of the computer.

I tried sp_addserver 'new server name' syntax, and restarted the SQL Service; still it reflects the old name? what am i missing?
0
 
dqmqCommented:
what do you see here:

Select hostname(), * from sys.servers

Pay attention to the local host,  id=0, which is where @@servername comes from




0
 
anushahannaAuthor Commented:
dqmq,
I get
'hostname' is not a recognized built-in function name.

>> id=0, which is where @@servername comes from

after giving a new name with sp_addserver and restarting sql service, what is incomplete that the change has not yet occurred?

thanks
0
 
dqmqCommented:
sorry, should have been
Select host_name(), * from sys.servers
0
 
NormanMainaCommented:
anushahanna:The question you asked originally did not suggest you had a problem with your server name.

A couple of questions to help understand your problem.
1)what version of sql server have you installed that you want to rename?
2)start a new quesry on ssms and type:sp_helpserver :then execute
This will show you the installed instances in your machine
What instance do you want to rename?
3)Run the below code get your server name,your instance name,hostname and port.

set nocount on

Declare @key Varchar(100), @PortNumber varchar(20)

if charindex('\',CONVERT(char(20), SERVERPROPERTY('servername')),0) <>0

begin

set @key = 'SOFTWARE\MICROSOFT\Microsoft SQL Server\'+@@servicename+'\MSSQLServer\Supersocketnetlib\TCP'

end

else

begin

set @key = 'SOFTWARE\MICROSOFT\MSSQLServer\MSSQLServer\Supersocketnetlib\TCP'

end

EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key=@key,@value_name='Tcpport',@value=@PortNumber OUTPUT

SELECT CONVERT(char(20), SERVERPROPERTY('servername')) ServerName,

CONVERT(char(20), SERVERPROPERTY('InstanceName')) instancename,

CONVERT(char(20), SERVERPROPERTY('MachineName'))

as HOSTNAME, convert(varchar(10),@PortNumber) PortNumber

0
 
anushahannaAuthor Commented:
NormanMaina, thanks for your feedback on those points.

Yes, I can see I am going outside of what I asked. it is like at least 2 questions in one post;
and you had already helped me with the solution. sorry for the confusion.

I have put the follow question below:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_26423214.html
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_26423215.html

Thanks again to all the experts.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now