Thursday, November 16, 2006

How to change object owner to dbo for several database objects at once

The output from the following SQL statement will generate code for any non-DBO onject and change the owner to dbo

SELECT 'EXEC(''sp_changeobjectowner @objname = '''''+ ltrim(u.name) + '.' + ltrim(s.name) + '''''' + ', @newowner = dbo'')' FROM sysobjects s, sysusers u WHERE s.uid = u.uid AND u.name <> 'dbo'AND xtype in ('V', 'P', 'U')AND u.name not like 'INFORMATION%'order by s.name

資料來源

0 Comments:

Post a Comment

<< Home