Script the granting of server roles to a SQL Server Login

131 views Asked by At

I have a script that creates a login in SQL Server as follows:

CREATE LOGIN [MyDomain\MyUser] FROM WINDOWS WITH DEFAULT_DATABASE=[master],
DEFAULT_LANGUAGE=[us_english]
GO

Is it possible to add to this script the granting of server roles? I want to grant the sysadmin server role to this user

1

There are 1 answers

0
bjnr On BEST ANSWER

By using sp_addsvrrolemember stored procedure:

EXEC master..sp_addsrvrolemember @loginame = N'MyDomain\MyUser', @rolename = N'sysadmin'