Create a New Login

  • Hello Everyone

    I am creating a couple new logins on a Database box. I want to limit what they can do, so I have added them only to the "dbcreator" database role. But there are hundreds of databases on this box. How can I script this to give dbo role membership for each database? While still granting the login as a "dbcreator" role?

    I have a few databases boxes like this, and I would rather not have to perform this task by hand in the future.

    Thanks in advance

    Andrew SQLDBA

  • You can generate script using this query:

    use master

    go

    SELECT 'EXEC [' + name + '].dbo.sp_grantdbaccess ''login'', ''userNameInDB''' from sysdatabases

    SELECT 'EXEC [' + name + '].dbo.sp_addrolemember ''db_owner'', ''SuperUserLogin''' from sysdatabases

    Run the output to add user to each database as db_owner.

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

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