Important alert: (current site time 7/15/2013 7:08:52 PM EDT)
 

VB icon

Changing object owner to dbo

Email
Submitted on: 11/9/2003 2:24:43 PM
By: Mike J Anderson 
Level: Beginner
User Rating: By 1 Users
Compatibility: SQL Server 2000, SQL Server 7.0
Views: 20558
(About the author)
 
     Use this one liner to change object owner to dbo (rights).
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
--**************************************
-- Name: Changing object owner to dbo
-- Description:Use this one liner to change object owner to dbo (rights).
-- By: Mike J Anderson
--
-- Inputs:Input object name
--
-- Returns:Returns object as DBO
--
-- Assumes:Use this one liner to change object owner to dbo (rights).
--
--This code is copyrighted and has-- limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=782&lngWId=5--for details.--**************************************

sp_changeobjectowner 'mike.testing123',dbo


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
11/10/2003 4:31:41 PM

This fine if you only want to do this 1 or 2 objects in your database. However, if you have over 200 objects to accomplish this on, this becomes impractical real fast. If for example, you would like to do this for every table(or VIEW)in the current database, or only certain owners, or only certain object patterns, here is a slight variation to accomplish this quickly:

SELECT 'EXEC sp_changeobjectowner ''' + TABLE_SCHEMA + '.' + TABLE_NAME + ''', dbo'
FROM INFORMATION_SCHEMA.TABLES
WHERE
OBJECTPROPERTY(OBJECT_ID(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)), 'IsMSShipped') = 0
AND TABLE_TYPE = 'BASE TABLE'
-- or 'VIEW' if it is a view
--AND TABLE_SCHEMA = 'Admin'
-- or to only change the owner of tables owned by 'Admin' only
--AND TABLE_NAME LIKE 'Tbl%'
-- ot to only change the owner of tables starting with a particular pattern
GO

(If this comment was disrespectful, please report it.)

 
5/30/2009 8:42:11 AMCHOSEN

i love makeing a good research and meeting new people.
chris
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.