Epic Puck

T-SQL Script ... list all tables owned != dbo

by on Nov.12, 2007, under Coding, SQL

DECLARE @oldOwner sysname, @newOwner sysnameSELECT @oldOwner = 'old_owner'

, @newOwner = 'dbo'

select 'EXECUTE sp_changeobjectowner '''+QUOTENAME(a.TABLE_SCHEMA)+'.'+QUOTENAME(a.TABLE_NAME)+''','''+@newOwner+''''

from

INFORMATION_SCHEMA.TABLES a

where

a.TABLE_SCHEMA = @oldOwner

AND

OBJECTPROPERTY(OBJECT_ID(QUOTENAME(a.TABLE_SCHEMA)+'.'+QUOTENAME(a.TABLE_NAME)), 'IsMSShipped') = 0

Be Sociable, Share!
:all tables not dbo, sample, sql, t-sql

Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!