Renaming a Table                                                                Administration TipsRenaming a TableThe bas...
Upcoming SlideShare
Loading in...5
×

Tablerename

164

Published on

oracle foreign key primary key constraints performance tuning MTS IOT 9i block size backup rman corrupted column drop rename recovery controlfile backup clone architecture database archives export dump dmp duplicate rows extents segments fragmentation hot cold blobs migration tablespace locally managed redo undo new features rollback ora-1555 shrink free space user password link TNS tnsnames.ora listener java shutdown sequence

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
164
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Tablerename

  1. 1. Renaming a Table Administration TipsRenaming a TableThe basic command to do this is:ALTER TABLE SCHEMA.TABLE_NAME RENAME TO SCHEMA.NEW_TABLE_NAME;That command is guaranteed to work only in Oracle 8i and 9i -youll have to experiment tosee if it works on 8.0 or earlier versions.Issuing this command does not invalidate any indexes, constraints or permissions grantedon the original table.For example, if Fred has been granted select privileges on the EMP table, and the EMPtable is then renamed to be EMPLOYEES, Fred will now be able to select from EMPLOYEESwithout further grants being needed.Whilst indexes and constraints are all still valid and useable after a table is renamed, theyretain their original names. For example, if you created a constraint called EMP_ID_PK, itwill still be called that, even though it is now a constraint on the EMPLOYEES table.Similarly, an index called EMP_PK retains that name, regardless of the fact that the tableit is an index of has changed its name.You might therefore want to issue the command:ALTER INDEX SCOTT.EMP_PK RENAME TO SCOTT.EMPLOYEES_PK;However, there is no rename command for constraints, and hence they must retain theiroriginal names, unless you drop them and re-create them.Finally, renaming a table means performing DDL on a table -and performing DDL to anytable renders all procedures, packages and triggers that reference the table invalid. Youcan check that by looking at the STATUS column of the DBA_OBJECTS view. All invalidpackages, procedures and triggers are automatically recompiled the first time they arecalled after their invalidation (subject to some provisos), but you can also manuallyrecompile them if you wish: ALTER TRIGGER BLAH COMPILE;, for example.Incidentally, if you query DBA_TRIGGERS (as an example), you can see the code making upa particular trigger (in the TRIGGER_BODY column) -and youll discover that what was oncetyped in as create trigger blah before update on emp automatically gets re-jigged byOracle to read ...update on employees. The rename command therefore even re-writesyour code for you, which is nice!Copyright © Howard Rogers 2001 10/17/2001 Page 1 of 1

×