?
Solved

How to change owner permissions from ________ to dbo

Posted on 2004-09-02
8
Medium Priority
?
920 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 69

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 69

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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

752 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