Sql-server – Sysadmin rights to local administrator

sql serversql server 2014

How I can give the sys_admin rights to the local administrator for the SQL Server 2014 database while I installed it using the domain admin account, not local administrator account? Below is the requirement of a manual.

SQL Server installation

During the installation of AlarmInsight
components it is required to use local Administrator login. The SQL
Server Installation can also be done with local Administrator login by
giving required access rights. If another login is used to install SQL
Server, the local Administrator has to be given sys_admin rights in
the SQL Server Database.

Best Answer

I had to reread the vendor requirements a couple of times, but I take the instructions to mean the local administrator account only requires elevated permissions during installation. Run one of the following blocks prior to the app install to set this up.

-- Add the Local Administrators Group
USE [master]
GO
CREATE LOGIN [BUILTIN\Administrators] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
GO
ALTER SERVER ROLE [sysadmin] ADD MEMBER [BUILTIN\Administrators]
GO

-- Or Add only the Local Administrator User - Dynamic SQL to capture servername
DECLARE @hostname NVARCHAR(128), @createStmt NVARCHAR(MAX)
SELECT @hostname = CAST(SERVERPROPERTY(N'ComputerNamePhysicalNetBIOS') AS NVARCHAR(128))

SET @createStmt = N'USE [master];' + CHAR(13) + CHAR(10) +
    N'CREATE LOGIN [' + @hostname + N'\Administrator] FROM WINDOWS WITH DEFAULT_DATABASE=[master];' + CHAR(13) + CHAR(10) +
    N'ALTER SERVER ROLE [sysadmin] ADD MEMBER [' + @hostname + N'\Administrator];'

PRINT @createStmt
EXECUTE (@createStmt)
GO

When the installation is complete, be sure to back out these permissions as they are not the most secure, by running one of the following:

-- Drop Local Administrators group
USE [master]
GO
DROP LOGIN [BUILTIN\Administrators]
GO

-- Or Drop the explicitly defined Local Administrator login
DECLARE @hostname NVARCHAR(128), @createStmt NVARCHAR(MAX)
SELECT @hostname = CAST(SERVERPROPERTY(N'ComputerNamePhysicalNetBIOS') AS NVARCHAR(128))

SET @createStmt = N'USE [master];' + CHAR(13) + CHAR(10) +
    N'DROP LOGIN [' + @hostname + N'\Administrator];'

PRINT @createStmt
EXECUTE (@createStmt)
GO