USP_SYSTEMROLEAPPUSER_SETSYSADMIN
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@SID | varbinary | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@SYSADMIN | bit | IN |
Definition
Copy
create procedure dbo.USP_SYSTEMROLEAPPUSER_SETSYSADMIN
(
@SID varbinary(85),
@CHANGEAGENTID uniqueidentifier,
@SYSADMIN bit
)
as
--Makes (or un-makes) the specified user account a sysadmin in the APPUSER table.
--if the user does not have a row in the APPUSER table then one is added.
if @SID is null
begin
raiserror('User SID is required to make a user a SYSADMIN',16,1);
return 400;
end;
declare @ID uniqueidentifier;
if @changeAgentID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
select @ID=ID from dbo.APPUSER where USERSID = @SID;
if @ID is null
begin
set @ID=NEWID();
insert into dbo.APPUSER (ID,USERSID,ISSYSADMIN,ADDEDBYID,CHANGEDBYID,DATEADDED,DATECHANGED)
values(@ID,@SID,@SYSADMIN,@changeAgentID,@changeAgentID,GETDATE(),GETDATE());
end
else
begin
update dbo.APPUSER
set ISSYSADMIN=@SYSADMIN,
DATECHANGED=GETDATE(),
CHANGEDBYID=@changeAgentID
where ID=@ID;
end
return 0;