MTI TEK
  • Home
  • About
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • All Resources
Oracle SQL | Standard Tables (Heap-Organized)
  1. Creating Standard Tables
  2. Creating Tables from Queries (CTAS)
  3. Table Management Operations
  4. Performance Optimization with NOLOGGING
    1. NOLOGGING with CREATE TABLE
    2. NOLOGGING with ALTER TABLE
    3. NOLOGGING with CREATE TABLE AS SELECT
  5. Performance Optimization with PARALLEL
    1. PARALLEL with CREATE TABLE
    2. PARALLEL with ALTER TABLE
    3. PARALLEL with CREATE TABLE AS SELECT

  1. Creating Standard Tables
    Heap-organized tables are the default and most common table type in Oracle Database. They store data in an unordered heap structure where new rows are inserted into available free space.
    CREATE TABLE table_test_1
    (
        pkid NUMBER(1,0) NOT NULL
    ,   code VARCHAR2(2) NOT NULL
    );
    
    Verify table creation and examine its properties in the data dictionary:
    SELECT table_name, tablespace_name, degree, logging, num_rows, blocks, avg_row_len
    FROM user_tables
    WHERE table_name = 'TABLE_TEST_1';
    
    Query result:
    | TABLE_NAME   |  TABLESPACE_NAME   | DEGREE | LOGGING | NUM_ROWS | BLOCKS | AVG_ROW_LEN |
    +--------------+--------------------+--------+---------+----------+--------+-------------+
    | TABLE_TEST_1 | USERS              | 1      | YES     | (null)   | (null) | (null)      |
    
    Note:
    • TABLESPACE_NAME: Physical storage location (defaults to user's default tablespace).
    • DEGREE: Parallel processing degree (1 = serial processing).
    • LOGGING: Whether redo information is generated for table operations.
    • NUM_ROWS, BLOCKS, AVG_ROW_LEN: Statistics populated after data is inserted and analyzed.
  2. Creating Tables from Queries (CTAS)
    CREATE TABLE AS SELECT (CTAS) is a powerful feature that creates a new table and populates it with data from a query in a single operation. This is particularly useful for creating backup copies, summary tables, or transforming data structures.
    Simple CTAS Example:
    CREATE TABLE table_test_2 AS
    SELECT pkid, code FROM table_test_1;
    
    Complex CTAS with Joins and Transformations:
    CREATE TABLE table_test_3 AS
    SELECT t1.pkid, (t1.code || t2.code) AS code_new_name
    FROM table_test_1 t1
    JOIN table_test_2 t2 ON t2.pkid = t1.pkid;
    
  3. Table Management Operations
    Oracle provides several DDL operations for managing existing tables, including renaming and dropping operations. These operations require appropriate privileges and consideration of dependent objects.
    Renaming Tables:
    ALTER TABLE table_test_2 RENAME TO table_test_2_new_name;
    
    Important Considerations for Table Renaming:
    • Indexes and constraints are automatically renamed to reflect the new table name.
    • Grants on the table are preserved with the new name.
    • All dependent objects (views, synonyms, stored procedures) become invalid.
    Dropping Tables:
    DROP TABLE table_test_1;
    
    Recycle Bin Management:
    Dropped tables are moved to the Recycle Bin by default, allowing for recovery if needed. Use DROP TABLE table_name PURGE; to permanently drop the table and bypass the Recycle Bin.
    DROP TABLE table_test_1 PURGE;
    
    Drop table and all dependent constraints:
    DROP TABLE table_test_1 CASCADE CONSTRAINTS;
    
  4. Performance Optimization with NOLOGGING
    The NOLOGGING option can improve the performance of bulk data operations such as CREATE TABLE AS SELECT, INSERT with direct-path, and bulk loads. This option instructs Oracle not to write minimal information to the REDO LOG file for certain operations, which can improve performance and save redo log space. Note that NOLOGGING operations may affect database recovery.
    1. NOLOGGING with CREATE TABLE
      Create tables with NOLOGGING mode for subsequent bulk operations:
      CREATE TABLE table_logging_1
      (
          pkid NUMBER(1,0) NOT NULL
      ,   code VARCHAR2(2) NOT NULL
      ) NOLOGGING;
      
      Note: The table structure creation is always logged; NOLOGGING affects subsequent DML operations like INSERT /*+ APPEND */.
    2. NOLOGGING with ALTER TABLE
      Toggle logging mode for existing tables:
      ALTER TABLE table_logging_1 NOLOGGING;
      
      ALTER TABLE table_logging_1 LOGGING;
      
    3. NOLOGGING with CREATE TABLE AS SELECT
      Combine table creation and data loading with minimal logging:
      CREATE TABLE table_logging_2 NOLOGGING AS
      SELECT pkid, code FROM table_test_1;
      
  5. Performance Optimization with PARALLEL
    The PARALLEL option allows Oracle to execute operations using multiple parallel execution servers, which can improve performance for operations such as table scans, sorts, and DML operations on large tables. Parallel processing is most effective on systems with multiple CPUs and sufficient I/O bandwidth.
    1. PARALLEL with CREATE TABLE
      Create tables with parallel processing enabled for future operations:
      CREATE TABLE table_parallel_1
      (
          pkid NUMBER(1,0) NOT NULL
      ,   code VARCHAR2(2) NOT NULL
      ) NOLOGGING PARALLEL 3;
      
    2. PARALLEL with ALTER TABLE
      Modify parallel settings for existing tables:
      ALTER TABLE table_parallel_1 PARALLEL 3;
      
      ALTER TABLE table_parallel_1 NOPARALLEL;
      
    3. PARALLEL with CREATE TABLE AS SELECT
      Combine parallel processing with NOLOGGING for maximum performance:
      CREATE TABLE table_parallel_2 NOLOGGING PARALLEL 3 AS
      SELECT pkid, code FROM table_test_1;
      
© 2025 mtitek