Volatile Tables dgd

Embed Size (px)

Citation preview

  • 8/10/2019 Volatile Tables dgd

    1/3

    Volatile tables

    Volatile temporary tables:

    Uses Spool space.

    No data dictionary access needed.

    Table definition is kept in cache.

    Table is local to session and not the query.

    Table can be used multiple times with in the session.

    Volatile tables can be dropped any with within the session using DROP TABLE.

    However if we dont the table will get dropped automatically at the end of the

    session.

    The volatile table must be explicitly created using the CREATE VOLATILE TABLE

    syntax.

    Volatile tables dontsurvivesystem restart.

    Example of creating volatile table.

    CREATE VOLATILE TABLE V_TEMP, NO FALLBACK

    (

    Empid integer,

    Salary decimal(10,2)

    Deptno integer

    ) ON COMMIT PRESERVE ROWS;

    Note the highlighted 'ON COMMIT PRESERVE ROWS' allows us to use the same volatile

    table again and again within the session.

    BY default its 'ON COMMIT DELETE ROWS' , which means the data will be deleted

    after the query is committed.

    For volatile tables we can also request a NO LOG option which means

    thetransactionjournal will not be used.

    Example

    CREATE VOLATILE TABLE V_TEMP, NO FALLBACK , NO LOG

    (

    Empid integer,

    Salary decimal(10,2)

    Deptno integer

    ) ON COMMIT PRESERVE ROWS;

    LOG is default. Which means transaction journal will be maintained.

  • 8/10/2019 Volatile Tables dgd

    2/3

    Irrespective of whether we explicitly specify or not the volatile tables are created

    under userid logged in.

    CREATE VOLATILE TABLE username.table1 --> (Explicit)

    CREATE VOLATILE TABLE table1 --> (Implicit)CREATE VOLATILE TABLE databasename.table1 --> This will give is an error message if

    the databasename specified is not actually the username.

    Different sessions can use the same volatile table name. But a volatile table

    cannot use a name that is used by any of the following objects under the user id.

    Permanent tables.

    Temporary tables.

    Views.

    Macros.

    We can create volatile tables with FALLBACK, however as these tables dont

    survive system restart having fallback does not add much value. On the contrary

    they would take twice the spool space.

    We cannot use following while creating Volatile tables

    a. Permanent Journaling

    b. Referentialintegrity.Referential integrity means relation between

    tables, which is stored in DBC. As volatile table dont need data dictionary wecannot have referential integrity

    c. Check constraints

    d. Column compression.

    CREATE VOLATILE TABLE TEST1 ( salary integer compress 0 ) on commit

    preserve rows;

    Above query would fail with below message:

    CREATE TABLE Failed. 3706: Syntax error: COMPRESS option not allowed for a volatile

    table.

    e. Default values for columns

    CREATE VOLATILE TABLE TEST1 ( salary integer default 0 ) on commit

    preserve rows;

    Above query would fail with below error message:

    CREATE TABLE Failed. 3706: Syntax error: DEFAULT option not allowed for a volatiletable.

  • 8/10/2019 Volatile Tables dgd

    3/3

    f. Column titles

    g. Namedindexes.

    We cannot use HELP DATABASE command to find all the volatile tables under auserid. Reason being volatile tables are not stored in data dictionary

    To do that we have to use the command HELP VOLATILE TABLE ;

    This will show all the volatile tables under a particular user id.

    HELP VOLATILE TABLE;

    Table Name Table Id

    TEST1 06C4AA600000

    Following are the commands that we cannot run on VT's

    a. HELP and COLLECT STATS: This is no longer true with TD13. With TD13

    we can collect stats on volatile table.

    b. CREATE/DROP INDEX : we cannot have indexes on volatile table.

    c. ALTER TABLE.

    ALTER TABLE TEST1 ADD salary decimal(10,2)

    Following is the error we would get

    ALTER TABLE Failed. 5341: Volatile table 'TEST1' not allowed in statement.

    d. GRANTand REVOKE privileges

    Volatile tables cannot be renamed.

    Volatile tables cannot be loaded using multiload.