web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Automating User Enablement after Database Refresh Using SQL Script

(1) ShareShare
ReportReport
Posted on by 14
Hello All,
We have around 15-20 environments where database is refreshed twice a month. After database refresh, all users are disabled by default, and only admin is enabled. This is expected behavior.
Our customer wants to enable only a specific set of users in non-prod environment. For e.g. 50/100
Currently, we’re exporting list of enabled user from UserInfo form, and after database refresh, we're enabling each user manually from user info form.
Is there a quick way to achieve it via sql script?
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at
    Yes, of course that you can use SQL to manipulate data in SQL databases.
    I think you just need to change the value of Enable field in UserInfo table.
  • Verified answer
    Community member Profile Picture
    7 on at

    Thanks for your reply. I agree we can turn the value from 0 to 1 in field enabled. For e.g.

    Update userinfo set enable=1 // this statement will enable all the users in table.

    But our situation is a bit tricky. We don’t want to enable all the users. We have a list of users that needs to be enabled.

    We're thinking to run a sql script before database refresh, and the output of script should be run on database after refresh to enable only users which was enabled before DB refresh. Can this be achieved by sql script? 

  • Suggested answer
    Mohit Rampal Profile Picture
    12,573 Moderator on at
    Hi, If you want specific users to enable then probably you can create a User Group and add users that should be enabled after database refresh. Create sql script to enable only users added in that user group.
     
    To enable all users, you can use below sql script
    update UserInfo
    set Enable = 1
    To enable specific users you can use below sql script. Replace 'Test' with GroupId
     
    update UserInfo  
    set Enable = 1
    From UserInfo
    join userGroupList
    On userGroupList.USERID = UserInfo.ID
    AND userGroupList.GROUPID = 'Test'
     
     
  • Suggested answer
    Community member Profile Picture
    14 on at
    @Martin Dráb on 10 Jul 2023 at 22:33:08 ,  Thanks for your reply. I agree we can turn the value from 0 to 1 in field enabled. For e.g.
     
    Update userinfo set enable=1 // this statement will enable all the users in table.
     
    But our situation is a bit tricky. We don’t want to enable all the users. We have a list of users that needs to be enabled.
     
    We're thinking to run a sql script before database refresh, and the output of script should be run on database after refresh to enable only users which was enabled before DB refresh. Can this be achieved by sql script?
  • Community member Profile Picture
    14 on at
    @Mohit Rampal on 11 Jul 2023 at 12:00:46
     
    Thank you very much Mohit Rampal.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 669

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 445 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 331 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans