DBO vs. as owner

  • I created a Sql 7 test database for one of our developers. I made him dbo-equivalent for the database. When he creates a stored procedures (say "sp_doit") it lists him, not dbo, as the owner. His Sql code has lines like... " EXEC sp_doit" and the command

    fails because it can't find the stored procedure.

    1. I thought that "EXEC sp_doit" is equivalent to "EXEC dbo.sp_doit." He is dbo equivalent. Why doesn't it work?

    2. For the moment, I execute "sp_changeobjectowner <username>.sp_doit', 'dbo'" and his code works. But I don’t want to do this routinely. Suggestion appreciated.

    Bill

  • You'll have to "alias" him as dbo, not just give him dbo level access. You're right about exec, but it's really doing 'exec hislogin.objectname'. To do this, you need to remove the user from the db, then run this:

    EXEC sp_addalias 'his login', 'dbo'

    He'll have dbo access and all objects will be owned by dbo. When work is done, you can remove it with sp_dropalias.

    The other alternative is to make him the actual db owner. I normally keep all mine owned by SA, but it's convienient in some cases. Just use sp_changedbowner to do it. After that he IS the dbo.

    Andy

  • Andy,

    Does the statement:

    EXEC sp_addalias 'his login', 'dbo'

    only work for SQL 7 server not SQL 2000?

  • Should workin both. Are you getting an error? Perhaps he still has a login in the db.

    Steve Jones

    steve@dkranch.net

  • Steve's right, should work in both though I don't have a SQL7 install to test on. It will fail if the login is already in the db as a user. Getting an error message you can post?

    Andy

  • No. I don't get any error. The problem is that even after running

    EXEC sp_addalias 'domain\userx', 'dbo'

    All the db objects created by userx still owned by 'domain\userx' not by 'dbo'.

  • I have tested the behavior I described in my last posting in a Win2k/SQL2k environment. And I know that If users prefix dbo. in any db object he/she created then the object IS owned by dbo. But we don't want to use prefixing all the objects with 'dbo.'

  • Do you mean new objects, or existing objects?

    Existing ones will have to be changeed with sp_changeobjectowner

    Steve Jones

    steve@dkranch.net

  • When userx created a new db object after executing

    EXEC sp_addalias 'domain\userx', 'dbo'

  • Can you check sysusers and see what the entry is for this user?

    Steve Jones

    steve@dkranch.net

  • Yes I did. This userx is a

    * islogin

    * isntname

    * isntuser

    And the associated uid > 5

  • what about isalias?

    Which UID does the user have?

    Does this user have a role? a sid?I added a domain user and ran sp_addalias and it seemed to work. Will log off and try to create an object shortly.

    Steve Jones

    steve@dkranch.net

  • I logged in as my user and it worked. Check the altuid column as well. I have a 1 here for my aliased user.

    Steve Jones

    steve@dkranch.net

  • Thanks. I'll retry that again some time later. Is your aliased user a ntuser or a sqluser?

  • ntuser. didn't test sqluser.

    Steve Jones

    steve@dkranch.net

Viewing 15 posts - 1 through 15 (of 17 total)

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