Solved

DBO Owner vs. other users as the owner

Posted on 2004-08-27
5
1,334 Views
Last Modified: 2008-01-09
I manage an MSSQL 2000 Windows 2000 server with about 100 databases on it for various customers.  All of these customers manage their databases remotely via Enterprise Manager and scripts on their Web Sites that connect to the server.  Each database has a unique login that is in the public and db_owner roles of a particular database.  The problem is that some customers complain that when they create tables or transfer them from elsewhere with DTS, the owner is either dbo or the custom user for their database.  Which user is the owner varies based on reasons I am not aware of.  Some customers complain they cannot do certain things because the owner is dbo and others complain about the owner not being dbo.

Can someone explain what causes this discrepancy of owner and also what limitations this puts on functionality either way?

Thanks in advance,
Dan
0
Comment
Question by:easycgi
  • 3
  • 2
5 Comments
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
If you log into sql server with an user different than the db creating user,

(1) you need explicitly granted rights to access objects in this database

(2) all operations will first be applied to objects defined for that user, than for dbo. Creating tables will create a table for the user logged in, not for dbo.

Main approach to this is: use one account for schema definitions (this will be named internally as 'dbo'), another one for querying data.
0
 

Author Comment

by:easycgi
Comment Utility
Let me explain a specific situation in a little more detail.  We create the databases for the users manually logged into Enterprise Manager with the sa account.  We create their database and a login which has public and db_owner rights to that database only.  The customer then logs into the db server with Enterprise Manager remotely and creates his tables, objects, etc.  The problem is that he has scripts that reference all his tables as dbo like the following:

ALTER TABLE [dbo].[tbl_groupmaster]

When he creates his tables with his user (cdss), he would have to modify all his scripts to reference his tables like this:

ALTER TABLE [cdss].[tbl_groupmaster]

Is there any remedy or workaround for this?
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
(1) You could change ownership "manually":

declare csr cursor for select creator+'.'+name from sysadm.systables where creator <> 'DBO' and name not like 'SYS%' for read only;
declare @tbl varchar(32);
declare @sel nvarchar(4000);
open csr;
fetch csr into @tbl
while @@fetch_status = 0
begin
   print  @tbl;
   exec sp_changeobjectowner @tbl, 'dbo'
   fetch csr into @tbl
end
deallocate csr
commit;

Maybe (didn't try this) you might put this into a stored procedure, which could be executed by your client after creating things. I don't know which rights your client will need to do this, but this should be easy for you to find out :-)

(2) First create the user, than create the db as corresponding user.Each object created as tgha

0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
Sorry.
(2) First create the user, than create the db as corresponding user. Ech object createed as that user will be owned by dbo.
0
 

Author Comment

by:easycgi
Comment Utility
Option number 2 solved my problem.  Thanks so much.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now