[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to change owner permissions from ________ to dbo

Posted on 2004-09-02
8
Medium Priority
?
921 Views
Last Modified: 2008-03-17
I just switched SQL servers and my old stored procedures read dbo.whatever, etc. whereas some of my new tables aren't dbo they're mattbrigh

How do I change those to dbo or do I need to change my stored procedures to mattbrigh from dbo?
0
Comment
Question by:mattybrigh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 11968716
You'd be much better off changing the tables.

Use: EXEC sp_changeObjectOwner -- see Books Online for more details, or post a follow-up comment here :-) .
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 11968729
For example, to generate the commands:

SELECT 'EXEC sp_changeObjectOwner ''' + name + ''', ''dbo'''
FROM sysobjects
WHERE xtype = 'U'
AND USER_NAME(uid) <> 'dbo'
0
 

Author Comment

by:mattybrigh
ID: 11968766
And where would I enter that info.?  Query analyzer?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 18

Expert Comment

by:SjoerdVerweij
ID: 11968772
Yep.
0
 

Author Comment

by:mattybrigh
ID: 11968812
Is "+ name +" the table name?
0
 
LVL 34

Expert Comment

by:arbert
ID: 11968851
Just had this same question earlier today for views--look at the above post and change the 'VIEW' in the query to 'TABLE'


http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21116914.html
0
 

Author Comment

by:mattybrigh
ID: 11968879
No dice.  It runs in Query Analyzer and says it works, but when I look at my tables in Ent. Manager, the type is still "User" and the owner is still "mattybrigh"
0
 
LVL 1

Accepted Solution

by:
blobbles earned 2000 total points
ID: 11969228
Run this, it will change all your tables and procedures to dbo:

--*********************************
DECLARE @Name varchar(1000)
DECLARE @UID int

-- Declare a cursor and setup
DECLARE NameUpdate CURSOR LOCAL FAST_FORWARD
FOR
SELECT [Name], uid FROM sysobjects
WHERE Type <> 'S'
AND (xType = 'P' OR xType = 'U')
AND uid <> 1

-- Open the cursor
OPEN NameUpdate

-- Fetch the Data into the variables
FETCH NEXT FROM NameUpdate
INTO @Name,@UID

-- Loop through the duplicates setting the next duplicates deletedatetime
WHILE @@FETCH_STATUS = 0
BEGIN
      SET @Name = (SELECT name FROM sysusers WHERE uid = @UID) + '.' + @Name

      EXEC sp_changeobjectowner @Name, 'dbo'
      
      FETCH NEXT FROM NameUpdate
      INTO @Name,@UID

END

CLOSE NameUpdate
DEALLOCATE NameUpdate
--*****************************************************

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

656 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