Solved

@@servername - where does instance get that info

Posted on 2010-08-20
12
503 Views
Last Modified: 2012-05-10
is it the 'computer name' of the SQL Server? or how/where does it get that info from?

thanks
0
Comment
Question by:anushahanna
  • 3
  • 3
  • 2
  • +4
12 Comments
 
LVL 12

Accepted Solution

by:
mcv22 earned 63 total points
ID: 33490009
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
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 63 total points
ID: 33490015
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
 
LVL 42

Assisted Solution

by:dqmq
dqmq earned 125 total points
ID: 33490017
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
 
LVL 28

Assisted Solution

by:sammySeltzer
sammySeltzer earned 63 total points
ID: 33490021
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
 
LVL 2

Assisted Solution

by:rajeshprasath
rajeshprasath earned 62 total points
ID: 33490200
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
 
LVL 12

Assisted Solution

by:NormanMaina
NormanMaina earned 124 total points
ID: 33490329
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 6

Author Comment

by:anushahanna
ID: 33500662
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
 
LVL 42

Expert Comment

by:dqmq
ID: 33502463
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
 
LVL 6

Author Comment

by:anushahanna
ID: 33502749
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
 
LVL 42

Assisted Solution

by:dqmq
dqmq earned 125 total points
ID: 33503052
sorry, should have been
Select host_name(), * from sys.servers
0
 
LVL 12

Assisted Solution

by:NormanMaina
NormanMaina earned 124 total points
ID: 33503213
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
 
LVL 6

Author Comment

by:anushahanna
ID: 33504310
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now