Generating SQL Logins\users and permissions for a database

  • Hi There,

    Is there any script or SP that can generate user permissions for database\tables\SP's to be reapplied?

    Im trying to find a way of creating a single script that will output all the users and their permissions for a database so I can put it back later ( just like when you use management studio to generate a script for users and permissions and just like Idera's SQL Permissions application ).

    Here is my scenario:

    I am asked to restore a database that already exists ( overwrite the database ) from one server to another.

    1)Before I restore, I have to script out the current users and their permissions on the database.

    2)I restore the database ( RESTORE DATABASE [TEST] .......WITH REPLACE )

    3)I reapply the user permissions I scripted out earlier ( as they were before the restore )

    What I am looking for is a script or SP that takes all the current users in a database and generates a script based on their current permissions on a database ( like GRANT EXEC TO ON [dbo.StoredProcedure], EXEC sp_grantdbaccess..... )

    Does anyone know of a way to do this?:unsure:

  • Hi

    Review this article, it contains your requirements.

    http://www.sqlservercentral.com/scripts/Security/66129/

    SNM

    Try Free Microsoft SQL Server Data Collector & Performance Monitor.

    http://www.analyticsperformance.com[/url]

    @nalyticsperformance - Microsoft SQL Server & Windows Server Free Data Collector

  • You can use SMO Object Model to implement backup script, database restore and restore scripting.

    SNM

    Try Free Microsoft SQL Server Data Collector & Performance Monitor.

    http://www.analyticsperformance.com[/url]

    @nalyticsperformance - Microsoft SQL Server & Windows Server Free Data Collector

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply