Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 change the table name in sql

Author  Topic 

mavershang
Posting Yak Master

111 Posts

Posted - 2008-12-02 : 17:24:35
Could anyone tell me how to change the name of a existed table in SQL code?

for example: change the name of table A to B.

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-02 : 17:31:32
You can use sp_rename for this. Here is a simple example from SQL Server Books Online:

quote:

USE AdventureWorks;
GO
EXEC sp_rename 'Sales.SalesTerritory', 'SalesTerr';
GO



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mavershang
Posting Yak Master

111 Posts

Posted - 2008-12-02 : 17:46:37
Thanks a lot

quote:
Originally posted by tkizer

You can use sp_rename for this. Here is a simple example from SQL Server Books Online:

quote:

USE AdventureWorks;
GO
EXEC sp_rename 'Sales.SalesTerritory', 'SalesTerr';
GO



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Go to Top of Page
   

- Advertisement -