SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sp_rename error


sp_rename error

Author
Message
amrinea
amrinea
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 59
I incorrectly ran sp_rename in the following manner:

sp_rename 'Schema.Table', 'Schema.Table2'

Now the table is no longer accessible. It shows up in sysobjects as Schema.Table2 in the "name" column. I know I shouldn't have included the Schema name in the second part of the rename, but now that I have, it's inaccessible. Is there a way that I can repair my mistake. I've tried doing:

sp_rename 'Schema.Table2', 'Table', 'object'

But I get there error:

Either the parameter @objname is ambiguous or the claimed @objtype (object) is wrong.
Steve Jones
Steve Jones
SSC Guru
SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)SSC Guru (148K reputation)

Group: Administrators
Points: 148210 Visits: 19444
Everything is in a schema. Likely it was in the dbo schema, so change it back to that one.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Lowell
Lowell
SSC Guru
SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)

Group: General Forum Members
Points: 73103 Visits: 40960
ok this was kewl to know;
once you doink up an object name so it has a dot in it, you need your brackets around the object, and it was easier for me to visualize with three part naming convensions to undo the damage;



CREATE SCHEMA bob
GO
CREATE TABLE bob.Test (
testid int,stuff varchar(50) )
GO
exec sp_rename 'bob.Test', 'bob.Test2' --created bob.[bob.Test2]

--try to fix, this fails no object found:
exec sp_rename 'bob.bob.Test2'

--works, due to brackets
exec sp_rename 'bob.[bob.Test2]'
--select from the object with 3 part naming:
select * from [SandBox].[bob].[bob.Test2]
--rename the object successfully
exec sp_rename '[SandBox].[bob].[bob.Test2]','Test2'




Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
amrinea
amrinea
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 59
Perfect Lowell. That's exactly what I was looking for. I kept trying various things, but didn't think to fully qualify it.

Thanks,
Adam
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search