Creating an Index Organized Table (IOT) using CREATE TABLE AS SELECT (CTAS)

Creating an Index Organized Table (IOT) using CREATE TABLE AS SELECT (CTAS)

This tip originates from a response posted by an Oracle support professional, Giribabu Bhamidipati, in the PL/SQL forum on Metalink.

This script has been tested on Oracle 8.1.7 for a data migration. Data was taken from multiple tables and combined into a final table. We used CREATE TABLE AS SELECT (CTAS) to create intermediate tables, which were joined to make a final table. Because of the final join, it was necessary to make the intermediate tables Indexed Organized Table (IOT). We used CTAS for speed.

The syntax for creating an IOT from an existing table using CTAS may be a little different from what you are used to when creating a table. The following is an example:

 CREATE TABLE iot_emp ( employee_id PRIMARY KEY, first_name, last_name ) ORGANIZATION INDEX TABLESPACE mytable AS SELECT employee_id, first_name, last_name FROM emp;

When you use CTAS to create an IOT, you do not specify the column data types.

The script above will work for a single column primary key. If you need to create a multicolumn primary key, use the following syntax:

 CREATE TABLE iot_emp ( employee_id, first_name, last_name, CONSTRANT pk_iot_emp PRIMARY KEY(employee_id, last_name) ) ORGANIZATION INDEX TABLESPACE mytable AS SELECT employee_id, first_name, last_name FROM emp;

As in the first example, you do not include the column data types. This format can also be used for a single column primary key.

    Requires Free Membership to View

    By submitting your registration information to SearchOracle.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchOracle.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

 

For More Information

  • Feedback: E-mail the editor with your thoughts about this tip.
  • More tips: Hundreds of free Oracle tips and scripts.
  • Tip contest: Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
  • Ask the Experts: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
  • Forums: Ask your technical Oracle questions--or help out your peers by answering them--in our active forums.
  • Best Web Links: Oracle tips, tutorials, and scripts from around the Web.


This was first published in August 2003

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.