Friday, December 9, 2022

After restore the DB from UAT or Prod to Dev Environment to Copy the admin user from Dev backup to new restored DB



DECLARE @SID NVARCHAR(124)

DECLARE @NetworkAlias NVARCHAR(255)

–Get the SID, NetworkAlias from the original database
SELECT
@SID = [SID],
@NetworkAlias = NetworkAlias
FROM [AxDB_Orig].[dbo].[UserInfo]
WHERE Id = ‘Admin’

–Restore the SID, NetworkAlias to the restored database
UPDATE [AxDB].[dbo].[UserInfo] SET
[SID] = @SID,
NetworkAlias = @NetworkAlias
WHERE Id = ‘Admin’