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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Can't get stored procedure to work

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2009-04-06 : 14:55:44
I'm getting incorrect syntax near the word to

Drop Table LastDiary
alter Table CurrentDiary to LastDiary

I want to drop the table LastDiary and change the name of CurrentDiary to LastDiary.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-04-06 : 14:58:29
You can't do that via ALTER TABLE. You can change the name with sp_rename.

From BOL:

quote:

Examples
A. Renaming a table
The following example renames the SalesTerritory table to SalesTerr.

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

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2009-04-06 : 15:11:41
Thanks got it:

Drop Table "LastDiary"
Exec sp_rename "Current", "LastDiary"
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-04-06 : 15:13:14
You're welcome.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-04-06 : 15:18:29
If you have a sproc dropping the table, there's probably one creating it. Would
TRUNCATE TABLE LastDiary
INSERT INTO LastDiary
SELECT <columns>
FROM CurrentDiary

work?

Jim
Go to Top of Page
   

- Advertisement -