How do I change the computer name stored in the SQL server database

Publication Date:  2016-11-21 Views:  353 Downloads:  0
Issue Description
How do I change the computer name stored in the SQL server database?
Solution
To change the computer name from SERVER_OLD to SERVER_NEW, proceed as follows:

1. Start the command-line interface, log in to the SQL Server database as the sa user (the password is password), and view the computer name.
osql -U sa -P password
select @@SERVERNAME
go
The original computer name SERVER_OLD is displayed.

2. Run the following commands to delete the original computer name SERVER_OLD and add the new computer name SERVER_NEW:
sp_dropserver @server='SERVER_OLD', @droplogins=NULL
go
sp_addserver @server='SERVER_NEW', @local='local',
@duplicate_ok='duplicate_OK'
go
exit

3. Restart the SQL Server service.

END