Friday 21 January 2011

To rename a computer that hosts a stand-alone instance of SQL Server

Once you have renamed your server from ServerA to ServerB you will notice that if you run the following:

SELECT @@SERVERNAME

You will still see that SQL thinks it is still called ServerA.

To resolve this you will need to run the following:

sp_dropserver ServerA
GO
sp_addserver ServerB, local
GO

Listing SQL Database File Locations

CREATE TABLE #Files (
[DatabaseName] sysname NOT NULL,
[name] [nchar] (128) NOT NULL,
[physical_name] [nchar] (260) NOT NULL
)
EXEC sp_msforeachdb 'Use [?] 
INSERT #Files 
SELECT "?", name, physical_name FROM sys.database_files'

SELECT * FROM #Files
ORDER BY #Files.DatabaseName

DROP TABLE #Files