After creating DB | Need to set the DB as db_owner

  • I have created a a DB using sql commands. and when i opened the user mappings the db_Owner check box is not checked in .. how can I check that option while creating the DB using scripts? or while creating the user by script (sql commands).. Please help me out

  • EXEC sp_defaultdb <Login Name>, <Database Name>

    Run it after both the login and the database exist

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I have tried this sp_defaultdb lsr, temp... but in user mappings only the public check box is showing as checked...

  • The proc doesn't assign rights to the DB. It just makes it the login's default database. You'll have to grant any rights you want the login to have.

    After running that, if you check the General tabl of the login, you should see the default DB set.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • If you already have the login created and are adding another db, you can use the proc below to make the user a member of db_owner:

    EXEC sp_grantdbaccess ' '

    GO

    EXEC sp_addrolemember 'db_owner', ' '

    GO

Viewing 5 posts - 1 through 4 (of 4 total)

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