Monday, March 26, 2012

Rename tables from query analyzer

I have SQL 2k and I would like to know if I can rename a table from SQL
query analyzer.
Thanks
DimitrisEXEC sp_rename 'customers', 'custs'
HTH. Ryan
"Dimitris Nikolakakis" <dn@.hol.gr> wrote in message
news:OnIXVmMeGHA.3900@.TK2MSFTNGP05.phx.gbl...
>I have SQL 2k and I would like to know if I can rename a table from SQL
>query analyzer.
> Thanks
> Dimitris
>|||And how can this be done when in query analyzer the current DB is different
than the databe of table?
I have tried:
EXEC sp_rename '[FACOM].[dbo].[AddressBook]',
'[FACOM].[dbo].[_FACAddressBook]'
but I get error:
Error: The qualified @.oldname references a database (FACOM) other than the
current database.
"Ryan" <Ryan_Waight@.nospam.hotmail.com>
news:%23mHbkqMeGHA.4276@.TK2MSFTNGP03.phx.gbl...
> EXEC sp_rename 'customers', 'custs'
>
> --
> HTH. Ryan
>
> "Dimitris Nikolakakis" <dn@.hol.gr> wrote in message
> news:OnIXVmMeGHA.3900@.TK2MSFTNGP05.phx.gbl...
>|||>From BOL
You can change the name of an object or data type in the current
database only.
Thanks
Ajay Rengunthwar
MCDBA|||sp_rename works with objects in the current database only
To switch database :-
USE dbname
HTH. Ryan
"Dimitris Nikolakakis" <dn@.hol.gr> wrote in message
news:eWDOXvMeGHA.4900@.TK2MSFTNGP02.phx.gbl...
> And how can this be done when in query analyzer the current DB is
> different than the databe of table?
> I have tried:
>
> EXEC sp_rename '[FACOM].[dbo].[AddressBook]',
> '[FACOM].[dbo].[_FACAddressBook]'
> but I get error:
> Error: The qualified @.oldname references a database (FACOM) other than the
> current database.
>
> "Ryan" <Ryan_Waight@.nospam.hotmail.com>
> news:%23mHbkqMeGHA.4276@.TK2MSFTNGP03.phx.gbl...
>|||To add to the other responses, you can also execute sp_rename (and other
system procs) in the context of another database by qualifying with the
target database name:
EXEC FACOM..sp_rename '[dbo].[AddressBook]', '_FACAddressBook'
Also, specify *only* the new object name as the @.newname parameter value.
Do not specify the owner and do not enclose the name.
Hope this helps.
Dan Guzman
SQL Server MVP
"Dimitris Nikolakakis" <dn@.hol.gr> wrote in message
news:eWDOXvMeGHA.4900@.TK2MSFTNGP02.phx.gbl...
> And how can this be done when in query analyzer the current DB is
> different than the databe of table?
> I have tried:
>
> EXEC sp_rename '[FACOM].[dbo].[AddressBook]',
> '[FACOM].[dbo].[_FACAddressBook]'
> but I get error:
> Error: The qualified @.oldname references a database (FACOM) other than the
> current database.
>
> "Ryan" <Ryan_Waight@.nospam.hotmail.com>
> news:%23mHbkqMeGHA.4276@.TK2MSFTNGP03.phx.gbl...
>

No comments:

Post a Comment