7

I'm new to SQL Server Compact edition. I'm using Compact edition 3.5. I tried renaming the table. But, I couldn't do that through the following query.

alter table tablename to newname

Plz, someone help me.........

hgulyan
  • 8,099
  • 8
  • 50
  • 75
Developer404
  • 5,716
  • 16
  • 64
  • 102

4 Answers4

8

Try this

sp_rename '[OldTableName]' , '[NewTableName]'

Check links below for more information

http://blog.sqlauthority.com/2008/08/26/sql-server-how-to-rename-a-column-name-or-table-name/

http://erikej.blogspot.com/2007/08/hidden-gem-rename-table.html

Good Luck!

UPDATE

Here you can find a similar question

How do I rename a table in SQL Server Compact Edition?

You can try this tool

http://www.primeworks-mobile.com/

or try this in visual studio

conn.Open();
SqlCeCommand cmd = new SqlCeCommand("sp_rename 'oldTable', 'newTable' ", conn);
cmd.ExecuteNonQuery();
conn.Close();
Community
  • 1
  • 1
hgulyan
  • 8,099
  • 8
  • 50
  • 75
  • Thanks. But, it is showing the error as cannot parse the query. I'm using visual studio 2008. I don't have front end to work with sql server 2008. . . – Developer404 May 18 '10 at 05:10
7

In Visual Studio:

  1. Right click on database file in Database Explorer
  2. Select new query
  3. Type: sp_rename 'oldName' , 'newName'
  4. Press Ctrl+R key
  5. Finish
Morteza
  • 2,378
  • 5
  • 26
  • 37
0

This works in Visual Studio 2010 Express:

Select Tables in the database explorer and right-click to get the contextual menu

Select New Request, this will open a new page in which you can type any sql request to your database, so you can now type something like

sp_rename 'oldname', 'newname'

Right-click again in this window and select Execute SQL in the menu, that's it!

Don't forget to refresh the database explorer view to see the new name

-3

Please copy this table and data to new table and then delete old table. Same logic with rename.

insert into New_TableName
select *
from Old_TableName
sjngm
  • 12,423
  • 14
  • 84
  • 114