Solved

How to change owner permissions from ________ to dbo

Posted on 2004-09-02
8
918 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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 500 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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql update 2 38
Connect Gridview column to Textbox in C# 2 41
Merge join vs exist 3 27
Inserting LocalDB Table to SQL Server C# 3 19
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

733 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