home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / database / oracle / 1563 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  1.9 KB

  1. Path: sparky!uunet!sun-barr!olivea!gossip.pyramid.com!pyramid!oracle!unrepliable!bounce
  2. From: sstephen@us.oracle.com
  3. Newsgroups: comp.databases.oracle
  4. Subject: Re: Changing Column Name
  5. Message-ID: <1992Sep11.225724.1@us.oracle.com>
  6. Date: 12 Sep 92 06:57:24 GMT
  7. References: <BuBryy.Ep8@well.sf.ca.us>
  8. Sender: usenet@oracle.us.oracle.com (Oracle News Poster)
  9. Distribution: usa
  10. Organization: Oracle Corporation, USA
  11. Lines: 34
  12. Nntp-Posting-Host: wrvms.us.oracle.com
  13. X-Disclaimer: This message was written by an unauthenticated user
  14.               at Oracle Corporation.  The opinions expressed are those
  15.               of the user and not necessarily those of Oracle.
  16.  
  17. In article <BuBryy.Ep8@well.sf.ca.us>, mharper@well.sf.ca.us (Michael J. Harper) writes:
  18. > This should be an easy one :-)
  19. > How do I change the name of a column in a table?
  20. > Michael J. Harper
  21. > mharper@well.sf.ca.us
  22.  
  23. Not so easy.  You could try,
  24.  
  25. create table my_temp as
  26. select a,b,c d from a_table;   -- table my_temp will have columns a,b,d
  27. drop table a_table;
  28. rename my_temp to a_table;
  29.  
  30. However, you would end up losing all synonyms, views, indexes, grants, and
  31. constraints in the process.  You could get around that by exporting the table
  32. with those objects, using the above statements, then import everything except
  33. the table.  But, this does not "rename" references to the column in views,
  34. synonyms, indexes and some grants.  I seem to remember the SQL1 standard saying
  35. that since columns rely on names, not position, that this operation was
  36. disallowed as an integrity violation, however, I have absolutely no proof that
  37. this is true, (and I know some databases allow this).
  38.  
  39. Most designers I know would do something like this :
  40.  
  41. alter table a_table add column d ...;  -- same as format for "c"
  42. update a_table set d = c;
  43. update a_table set c = NULL;
  44.  
  45. Then, wait until the next generation of your application to get rid of column
  46. C.
  47.  
  48. Scott Stephens  (from my own experience, NOT official word of my company)
  49.