Solved

SQL 2000, Object Owner Question

Posted on 2011-03-09
2
296 Views
Last Modified: 2012-05-11
Environment: Microsoft SQL Server  2000 - 8.00.2039 (Intel X86)   May  3 2005 23:18:38   Copyright (c) 1988-2003 Microsoft Corporation  Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 2)

 

Two logins on the system, sa and Fred.  Fred is a member of System Administrators.

 

Fred creates a new database, let’s call it Sales, done via a simple script in Query Analyzer (QA).

 

In Enterprise Manager (EM) when I right click on this database, select properties, I can see that Fred is the database owner.

 

Fred now creates a table with himself as the owner, something like the script below, this is done via QA with Fred as the user / login.

 


CREATE TABLE [Fred].[Customers] (

     …

)

GO
 

This is the only table in the database.

With Fred logged into QA, I’m expecting this select statement (A) to work.


SELECT * FROM Customers
 

But it errors out, with the following:

Server: Msg 208, Level 16, State 1, Line 1

Invalid object name 'Customers'.

 

The following select (B), does work.


SELECT * FROM Fred.CustomersI’ve got tons of Visual Basic 6 code that uses the select without the qualified database owner.  This code was written a long time ago, but now I’ve got to get back into it.   For some reason, the non-qualified select statement used to work and does work at many sites still running this code.  But in my development environment I get the “Invalid object name” error.  

I’d prefer to not change the VB6 code, seems like this should work, or at least used to work.

So, can I setup SQL so that when Fred logs in he can default to use the object he owns and successfully run statement A from above?
0
Comment
Question by:g_johnson
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35084586
for system admins and db_owners, the object prefix defaults to dbo
and from what I know, you cannot change that behavior, except removing Fred as db owner ....
0
 
LVL 4

Author Closing Comment

by:g_johnson
ID: 35084770
Thanks, that did the trick.  We had assumed that "Fred" was always a sys admin, but we were wrong.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
t-sql Joining Issue 10 35
Help Required 2 30
SQL Server Designer 19 39
sql server tables from access 18 17
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

776 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