Friday, March 30, 2012

renaming a table

I know you can rename a table using sp_rename, but what I'm not sure about i
s
how to specify which database.
I'm doing this in VB (or in C#, it doesn't matter).
I have a connection to the SQL Server.
I can Exec sp_rename and give it oldname and newname for the table, but how
am I making sure it's for a table within a particular database?Try:
exec MyDB.dbo.sp_rename 'MyTable', 'MyNewTable'
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Les Stockton" <LesStockton@.discussions.microsoft.com> wrote in message
news:7E260686-7AA8-49AF-A674-7F2073B35ABC@.microsoft.com...
>I know you can rename a table using sp_rename, but what I'm not sure about
>is
> how to specify which database.
> I'm doing this in VB (or in C#, it doesn't matter).
> I have a connection to the SQL Server.
> I can Exec sp_rename and give it oldname and newname for the table, but
> how
> am I making sure it's for a table within a particular database?|||Les,
The activity will take place in the database you are connected to. Client
interfaces allow you to specify the database (catalog) you are connected to.
Or, you could achieve this with T-SQL:
USE database_name;
EXEC sp_rename ...
Unfortunately, sp_rename doesn't allow you to specify the database name,
rather it will run in the context of the "current" database.
BG, SQL Server MVP
www.SolidQualityLearning.com
"Les Stockton" <LesStockton@.discussions.microsoft.com> wrote in message
news:7E260686-7AA8-49AF-A674-7F2073B35ABC@.microsoft.com...
>I know you can rename a table using sp_rename, but what I'm not sure about
>is
> how to specify which database.
> I'm doing this in VB (or in C#, it doesn't matter).
> I have a connection to the SQL Server.
> I can Exec sp_rename and give it oldname and newname for the table, but
> how
> am I making sure it's for a table within a particular database?

No comments:

Post a Comment