Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting help 1

Status
Not open for further replies.

bikerboy718

Programmer
Feb 11, 2005
195
US
I am trying to change the object owner of a table if the table exists where a certain user is the owner.

For example

IF exists db1.user1.table1
sp_changeobjectowner 'db1.user1.table1', 'user2'

When I use the exists key word i keep getting an error message. Can anyone direct me in fixing this up? Any help is greatlu appreciated.

Michael
 
try this one:

IF exists ( select 'x'
from sysobjects
where uid = (
select uid
from sysusers
where name = 'user1'
)
and name = 'table1' )
begin
sp_changeobjectowner 'db1.user1.table1', 'user2'
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top