Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 13th, 2005, 06:46 AM
Federico Chiesa Federico Chiesa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Italy
Posts: 2 Federico Chiesa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 39 m 23 sec
Reputation Power: 0
Renaming a table

Hi all,

I am migrating from MySQL to Firebird and despite the endless more features it has, I am having trouble making some of the most basic operations, even renaming a table. The super simple syntax:

ALTER TABLE oldname RENAME newname

just does not work. I have even checked IB Expert and it seems that there is nowhere to be found a way to rename a table. Google does not help either.

There is no way to rename a table besides creating a new table with the same fields, copying the data and then dropping the old table? This is a joke, right? Please tell me it is.

Reply With Quote
  #2  
Old July 13th, 2005, 07:22 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,917 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 15 h 7 m 10 sec
Reputation Power: 279
I don't think you can easily rename a table, and this should not be done unless you are playing around with your database.
Specific document
Table modifications you can do:
Code:
Alter table "Some_Name"
  Add "column_Name" Integer,            /* Add a new column              */
  Drop "xyz",                           /* Remove a column               */
  Alter column "Order" to "Sort_Order", /* changes the column name       */
  Alter column "Order" position 3,      /* changes the column's position */
  Alter column "Order" type VARCHAR(10),/* changes the column type       */
  Alter column "abc"   type d1          /* changes the column type       */
  ;
(ref)

Last edited by pabloj : July 13th, 2005 at 07:26 AM.

Reply With Quote
  #3  
Old July 13th, 2005, 07:37 AM
Federico Chiesa Federico Chiesa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Italy
Posts: 2 Federico Chiesa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 39 m 23 sec
Reputation Power: 0
Don't get me wrong, but renaming a table is a very common operation during development. If Firebird does not allow it, it does not make it an operation that you make "playing around with your database". I don't want to get into an argument here, but if the system you are accustomed does not allow something, it does not mean that what you are accustomed to is "the right way", it is just "the way you are accustomed to".

You can make a typo in your CREATE TABLE statement, or you can just decide for any reason that the name you originally gave to your table does is not suitable any more, for example because you added or dropped some columns.

Since you are a moderator of the MSSQL and Oracle forums, it would be interesting to know if these two DBMS's do allow table renaming. To me, this is such an obvious and common operation that I would have never even considered the possibility of having a RDBMS that does not allow it.

Reply With Quote
  #4  
Old July 13th, 2005, 08:02 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,917 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 15 h 7 m 10 sec
Reputation Power: 279
Wow, what a long response!
All I can say is that I'd always planned my table names (of course using a modeling tool helps) and never had an urgent need to rename them due to adding columns (a customer is always a customer, with ot without email or fax number ) of course I made typos, but got them checking created structures and fixed by drop/create.
Besides design time, renaming a table in a production system is generally impossible without breaking the applications running on top of it, this is why I think you should not rename table, the same for development time, if an even small portion of code has to be rewritten out of your change you'll be pointed as "the one who made us finish late" ...
All this makes me say that this is "the right way" of doing things and not "the way I'm accustomed to".


Both allow renaming, if you are interested in Oracle see this article

Last edited by pabloj : July 13th, 2005 at 08:12 AM.

Reply With Quote
  #5  
Old July 14th, 2005, 05:39 AM
SilverDB's Avatar
SilverDB SilverDB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Romania
Posts: 173 SilverDB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 45 m 53 sec
Reputation Power: 5
Send a message via Yahoo to SilverDB
You can follow these steps to change the name (not an easy way but it works):
1) create the table with the name that you want (new name)
2) import all the data from the old table (can use DataPump from IB_SQL for example)
3) drop the old table
and voila a new table name

P.S. A good programmer doesn't
Quote:
make a typo in his CREATE TABLE statement
as far as I see ...
__________________
If i've been helpful, please add to my reputation.
My unfinished site: http://www.dever.ro

Last edited by SilverDB : July 14th, 2005 at 05:43 AM.

Reply With Quote
  #6  
Old August 16th, 2008, 11:08 AM
softman softman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 4 softman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 42 sec
Reputation Power: 0
Hi

There is no alter table statement to rename tables, but you always can play with system tables (if you have access to it (sysdba) like this:

UPDATE RDB$RELATIONS
SET RDB$RELATION_NAME='NEWNAME' where
RDB$RELATION_NAME='OLDNAME';


UPDATE RDB$RELATION_FIELDS
SET RDB$RELATION_NAME='NEWNAME' where
RDB$RELATION_NAME='OLDNAME' and
RDB$SYSTEM_FLAG=0;

run both , than commit to database

I hope it helped
Bye


Quote:
Originally Posted by Federico Chiesa
Hi all,

I am migrating from MySQL to Firebird and despite the endless more features it has, I am having trouble making some of the most basic operations, even renaming a table. The super simple syntax:

ALTER TABLE oldname RENAME newname

just does not work. I have even checked IB Expert and it seems that there is nowhere to be found a way to rename a table. Google does not help either.

There is no way to rename a table besides creating a new table with the same fields, copying the data and then dropping the old table? This is a joke, right? Please tell me it is.
Comments on this post
pabloj disagrees: Thanks for digging a thread just to suggest manipulation of system tables ....

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Renaming a table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT