101communication LLC CertCities.com -- The Ultimate Site for Certified IT Professionals
   Certification Communities:  Home  Microsoft®  Cisco®  Oracle®  A+/Network+"  Linux/Unix  More  
    CertCities.com is proud to present our sponsor this month: Thomson Prometric
Editorial
Choose a Cert
News
Exam Reviews
Features
Columns
Salary Surveys
Free Newsletter
Cert on the Cheap
Resources
Forums
Practice Exams
Cert Basics
Links Library
Tips
Pop Quiz
Industry Releases
Windows Certs
Job Search
Conferences
Contributors
About Us
Search


Advanced Search
CertCities.com

CertCities.com
Let us know what you
think! E-mail us at:
.. Home .. Certifications .. Oracle .. Columns ..Column Story Thursday, August 21, 2003

TechMentor Conference & Expo PDF Brochure - Download It Now!

Save 30% on CertCities.com's Guide to IT Certification on the Cheap

 SELECTions   Damir Bersinic
Damir Bersinic



 Oracle 8i Features You Can Actually Use
There are many labor-saving improvements in Oracle 8i; in this column, Damir highlights new ways to reorganize tables and columns.
by Damir Bersinic  
3/25/2001 -- Recently, while teaching an Oracle 8i New Features for Administrators course, I was once again reminded how Oracle groups some of the most useful new features of the product in a module of that course called Miscellaneous Manageability Features. When I start talking about these features to the students attending the class, their usual reaction is "This is stuff I can use TODAY!" Here are some highlights in the "reorganizing columns and tables" area:

Reorganizing Tables
As a DBA, one of the tasks that you will need to perform periodically is monitoring the number of chained rows in a table, as well as its fragmentation. If either or both of these become too high, you will need to reorganize that table to ensure that you have good performance.

Prior to Oracle 8i, the two most common methods of doing this were to EXPORT, DROP and then IMPORT the table back into the database, or issue a CREATE TABLE & AS SELECT to create a new copy of the table, and then drop the original and rename the new one to the name of the original table. Both of these methods had some drawbacks, such as the requirement to either re-establish security or re-create indexes that were affected. The worst thing was that, while the reorganization was taking place, you were not allowed to access the tables, causing downtime for the database, or that portion of it.

In Oracle 8i a new command option was introduced to the ALTER TABLE syntax to address this issue specifically the MOVE option. With the ALTER TABLE <tablename> MOVE syntax it is now possible to reorganize the table while ensuring that security information and indexes are retained, and the table is accessible to users while the MOVE is being performed!! If your table was created on the ACCOUNTING tablespace, for example, and you wanted to move it to the new ACCOUNTING2 tablespace you just created on a new set of disks, you can issue the following command:

ALTER TABLE Customers MOVE TABLESPACE Accounting2

If you simply wanted to re-organize the table and keep it on the same tablespace, you can do that too by issuing the command:

ALTER TABLE Customers MOVE TABLESPACE Accounting

In either case, Oracle will rebuild the table in the target tablespace, allow users to query the existing table while the move is taking place, keep the existing permissions assigned to the table, and rebuild the indexes after the operation is completed. Optionally, you can also specify storage clause characteristics to change the extent sizes and other parameters (with the exception of FREELISTS or FREELIST GROUPS) if you find that the pervious storage parameters are no longer compatible with the table access and storage patterns.

Of course, there is a downside as well. Because the old copy of the table is kept until the move completes to allow queries to take place, this means that you will need sufficient disk space for both the old and new versions of the table typically double what was required before.

Note that the MOVE option of the ALTER TABLE syntax only applies to non-partitioned or index-organized tables. If you want to move partitions or sub-partitions to another tablespace, or reorganize them, you need to issue the ALTER TABLE & MOVE PARTITION or ALTER TABLE & MOVE SUBPARTITION commands for each partition or sub-partition.

Despite its main drawback the requirement for double the disk space this one command can make it extremely easy to reorganize tables for better performance without all the headaches of EXPORT and IMPORT or CREATE TABLE & AS SELECT.

Reorganizing Columns
While it has been possible to add new columns to an existing table in Oracle for quite a while now, until Oracle 8i it was not possible to drop or remove a column from a table without dropping the table first and then re-creating it without the column you wanted to drop. With this method, you needed to perform an EXPORT before dropping the table and then an IMPORT after creating it without the column, or issue a CREATE TABLE ... AS SELECT statement with all of its associated headaches (see above).

In Oracle 8i, we now have a way of marking columns UNUSED and then dropping them at a later date. Oracle is a little behind the times here compared to SQL Server, which does not require a complete rebuild of the table after dropping the column, but I'm just happy that I have the feature and hope that they'll improve it in Oracle 9i.

To get rid of columns with this new method, the first step is to issue the ALTER TABLE <tablename> SET UNUSED COLUMN <columnname>, which sets the column to no longer be used within the table but does not change the physical structure of the table. All rows physically have the column's data stored, and a physical place is kept for the column on disk, but the column cannot be queried and, for all intents and purposes, does not exist. In essence, the column is flagged to be dropped, though you cannot reverse setting the column to UNUSED.

It is possible to set a number of columns UNUSED in a table before actually dropping them. The overhead of setting columns UNUSED is fairly minimal and allows you to continue to operate normally, except that any actions on the UNUSED columns will result in an error. The next step, when you have configured all the columns you want to get rid of as UNUSED, is to actually physically reorganize the table so that the data for the UNUSED columns is no longer on disk and the columns are really gone. This is done by issuing the command ALTER TABLE & DROP COLUMN.

Physically dropping a column in an Oracle table is a process that will prevent anyone from accessing the table while the removal of the column(s) is processed. The commands that will affect an actual removal of a column are:

ALTER TABLE <tablename> DROP COLUMN <columnname>
ALTER TABLE <tablename> DROP UNUSED COLUMNS

The commands will always do the same thing. This means that if you mark two or three columns as UNUSED in a table, if you decide you want to drop one of them using the ALTER TABLE & DROP COLUMN command, you will drop ALL columns marked as UNUSED whether you want to or not. The ALTER TABLE & DROP COLUMN can also be used when a column has not previously been marked as UNUSED but you simply want to drop it right away, but you will also drop any UNUSED columns because that's the way it works.

If constraints depend on the column being dropped, you can use the CASCADE CONSTRAINTS option to deal with them; if you also want to explicitly mark views, triggers, stored procedures or other stored program units referencing the parent table and force them to be recompiled the next time they are used, you can also specify the INVALIDATE option.

A problem could arise if you issue the DROP COLUMN command and the instance crashes during the rebuild of the table. In this case, the table will be marked as INVALID and will not be available to anyone. Oracle forces you to complete the DROP COLUMN operation before the table can be used again. To get out of this situation, issue the command ALTER TABLE & DROP COLUMNS CONTINUE. This will complete the process and mark the table as VALID upon completion.

To Be Continued...
These are just a couple of the useful features that Oracle 8i provided us and are hidden in Oracle's documentation and courses. Use them they're really great. I'll tell you about some others in future columns.


Damir Bersinic is an independent consultant, trainer, and author of Oracle 8i DBA: SQL & PL/SQL Certification Bible (ISBN 0764548328), Oracle 8i DBA: Architecture and Administration Certification Bible (ISBN 0764548174) from Wiley & Sons, as well as a number of titles on Windows, Active Directory and SQL Server. He holds several industry designations including Oracle OCP DBA (in 4 Oracle versions), MCSE, MCDBA, MCT and CTT+. He can be reached at .

 

More articles by Damir Bersinic:

Post your comment below, or better yet, go to our Discussion Forums and really post your mind.
Current CertCities.com user Comments for "Oracle 8i Features You Can Actually Use"
3/28/01 - Aamir  says: Thanks a lot, Damir, for reminding me these useful features that I actually needed recently. Now I wouldn't have to search it up in my diary :).
6/5/01 - Eric  says: In your opinion, what would be the best way to learn Oracle programming and application development using Oracle quickly ? I have been using SQL-Server for the last 5 years or so. Thanks, Eric.-
7/4/01 - SAJI  says: Really very useful. This is what I am looking for. But I would also like to have option to change the unused to use it again in the future before giving a drop command
7/9/01 - Rahul  says: Tell me about RENAME a column in table. Thanks.
7/29/01 - GALIT  says: one drawback of the method of alter table ... move ... is that primary keys and indexes become invalid and you receive an error of ora-1502. a rebuild on the two must be issued right after the process
8/28/01 - HAYAT  says: hello sir, i want to use the import 8i utility to import only specific col of my table. the option may be as query=???????? please writhe the query or complete sysntax
8/30/01 - J.SHANKAR  says: Really excellent and you have put them across in a simple, clear way. If all starts writing like this learning oracle will be easy. Could you recommend the best way to become a DBA & where to look for good tips
9/27/01 - Anonymous says: But isn't it true that when using the ALTER TABLE MOVE command, you are not allowed to perform DML to the table?
9/27/01 - Kailash  says: Very nicely put ... wish the Oracle Manual(s) were in this format & language .. heck I wish all Manuals were written in this fashion. Please keep up the good work of postings like this on the internet. Makes life so much easier for lazy people like me. :) Thanx again
9/27/01 - Noman  says: It's best side 4 new comer
9/29/01 - C  says: Thanks Mr. Damir for letting us know one of the very useful features of Oracle8i. We look forward for more help from you. Thanks again Pavan.
4/28/02 - Anupam Ahuja  from India says: Can u rename a column which has data in oracle. I do not want to lose any data. + If column name is 'return'. will it effects the the database?
7/16/02 - Prasad Durvasula  from San Jose says: Thanks Damir for the useful info. But when we move tables to different tablespace using "parallel 4" option, some tables got corrupted. We do not have any clue and Oracle also did not help yet on this. Please give your input on this.
7/25/02 - Vijay Srinivasan  says: Excellent. You have put it so simple. So far, I never knew that we can delete a column in oracle. It was so tedious to delete a column. Is there any option other than drop in alter statements?
9/1/02 - Moses Moloi  from Botswana says: How can I disable all PK and FK constraints in table A (dependent on table B on foreign keys)prior to a delete from table B where there is no CASCADE ON DELETE specified on A?
9/12/02 - Jingjing  says: Our oracle817 installed on raw device (hp-ux 11.0),we find twice that a index becomes unusable after we rebuild it, no alter table or other operation, just when insert this table we receive ora-1502... I want to know why and how can solve it ?
9/13/02 - Shel  says: Excellent. Appreciate your effort in putting this up. Keep up the good work.
10/26/02 - Yan Zhang  from Canada says: I am very interested in "Reorganizing Tables". Could you please give me more information about ALTER TABLE MOVE. Heard you can't use this if there is Long, or long Raw columns existing in the tables, is that true?
Display Page: 01 02
Add your comment here:
Name: (optional)
Location: (optional)
E-mail Address: (optional)
Comments:  
 
top

Sponsored Link:
Don’t let your IT Investment Go to Waste: Get Certified with Thomson Prometric!

Home | Microsoft | Cisco | Oracle | A+/Network+ | Linux/Unix | MOUS | List of Certs
Advertise | Certification Basics | Conferences | Contact Us | Contributors | Features | Forums | Links | News | Pop Quiz | Industry Releases | Reviews | Tips
Search | Site Map | MCPmag.com | TCPmag.com | OfficeCert.com | TechMentor Conferences | 101communications | Privacy Policy
This Web site is not sponsored by, endorsed by or affiliated with Cisco Systems, Inc., Microsoft Corp., Oracle Corp., The Computing Technology Industry Association, Linus Torvolds, or any other certification or technology vendor. Cisco® and Cisco Systems® are registered trademarks of Cisco Systems, Inc. Microsoft, Windows and Windows NT are either registered trademarks or trademarks of Microsoft Corp. Oracle® is a registered trademark of Oracle Corp. A+®, i-Net+™, Network+™, and Server+™ are trademarks and registered trademarks of The Computing Technology Industry Association. (CompTIA). Linux™ is a registered trademark of Linus Torvalds. All other trademarks belong to their respective owners.
All content copyright 2000-03 101communications LLC, unless otherwise noted. All rights reserved.
Reprints allowed with written permission from the publisher. For more information, e-mail