|
You will, doubtless, at some point need to reorganize a table, move a table from one tablespace to another, redefine an entire table or portions of tables, or perform other interesting tasks. This section discusses these operations. Reorganizing TablesReorganizing tables can eliminate row migration both offline (as you have been able to historically) as well as online. Redefining TablesOccasionally you will need to redefine a table that is in production. Historically, you would have needed to lock the table in shared mode to perform this action. In effect, this shuts out all DML access. In Oracle 9i, you can now redefine tables while the database is online, and the table is accessible to DML operations for the duration of the process. During the redefinition process you can
There are, naturally, some restrictions for online redefinition. These include
Redefinition ProcessThe steps necessary to perform the online redefinition are as follows:
If you encounter any errors or if you want to abort the redefinition for any reason, you must invoke the ABORT_REDEF_TABLE procedure in the DBMS_ REDEFINITION package. Moving TablesIn Oracle 9i, you can now move nonpartitioned tables from one tablespace to another without the need to perform an export/import operation. After moving a table, you will have to rebuild the indexes to avoid having the indexes be in an unusable state. In this way, you can segregate hot tables off to their own tablespaces or distribute I/O over more devices. The command used to move a table to another tablespace is as follows: ALTER TABLE addresses MOVE TABLESPACE mydata2; Truncating TablesIf you want to remove all the data from a table, lower the high water mark, and still retain the definition of the table, you can issue the trUNCATE command to accomplish this: TRUNCATE TABLE addresses; You can, optionally, drop or reuse the storage associated with the truncated table to undefine the segments associated with the table. Because trUNCATE TABLE is a Data Definition Language (DDL) command, no undo is generated. Therefore, it is important that you be sure that you really want to truncate any table before you issue the command. Rolling back will not get the data back. For this same reason, ON DELETE TRiggers don't fire on a TRUNCATE command. The indexes that correspond to the table being truncated are also truncated (no data, no indexes).
Dropping TablesIf you simply want to remove the entire table from the database, you can issue the DROP TABLE command: DROP TABLE addresses; Again, remember that you cannot simply drop a table being referenced by a foreign key. We have now created a table, manipulated the table at the table level, and determined the way to proceed with some of the common maintenance that might need to occur on a table while that table is online. Now let's examine what can occur at the column level concerning maintenance. When the table is dropped, the extents used by the table are all released. Optionally, you can add the CASCADE CONSTRAINTS option if the table is the parent in a foreign key relationship. You can, similarly, make alterations to tables themselves. The following section addresses many of the operations that you can perform on the table's structure. |
|