Solved

SERVERPROPERTY('SERVERNAME') & SERVERPROPERTY('MACHINENAME')

Posted on 2010-08-23
5
285 Views
Last Modified: 2012-05-10
Are the above 2 always going to the same, guaranteed?

Are they absorbed at installation of SQL? or do they read from OS, live?

Thanks
0
Comment
Question by:anushahanna
  • 2
  • 2
5 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 334 total points
ID: 33503991
Nope.  The first will return the instance name while the 2nd returns the physical machine name.
0
 
LVL 6

Author Comment

by:anushahanna
ID: 33504008
so first one is from installation and second one is live?
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 334 total points
ID: 33504022
1st one is the instance.  So, say you have a machine named machine1.  On machine 1 you have 2 instances, the default and a named one (named Instance2).  If you run these on instance2, you'll get:

Machine1\Instance2
Machine1

however, if you run it on the default instance, they'll both return Machine1.  Make sense?
0
 
LVL 12

Assisted Solution

by:mcv22
mcv22 earned 166 total points
ID: 33504034
SERVERPROPERTY('MACHINENAME') is pulled from the OS. If you change the computer name, you will be prompted for a restart after which you would be able to see the new machine name if you run the query again.

SERVERPROPERTY('SERVERNAME') is initially set during SQL setup. It can however be changed at a later time by using sp_dropserver and sp_addserver 'newname', 'local'
0
 
LVL 6

Author Comment

by:anushahanna
ID: 33504152
Thanks very much for the clear diff between the two.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

828 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