TRUNCATE stored procedure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Swarbrick

    TRUNCATE stored procedure

    The following link includes an example of a stored procedure that can be
    used to truncate a table without logging:

    http://publib.boulder.ibm.com/infoce...topic=/com.ibm.
    db2.udb.apdv.sa mple.doc/doc/admin_scripts/s-truncate-db2.htm

    It uses "IMPORT FROM NUL OF DEL REPLACE INTO ...", where other examples of
    this type of thing seem to use LOAD instead of IMPORT.

    Any thoughts as to why one method might be prefered over the other?

    Frank

  • Troels Arvin

    #2
    Re: TRUNCATE stored procedure

    Frank Swarbrick wrote:
    It uses "IMPORT FROM NUL OF DEL REPLACE INTO ...", where other examples
    of this type of thing seem to use LOAD instead of IMPORT.
    The IMPORT-based method
    - requires less privileges than other methods
    - if fully recoverable

    See also http://groups.google.com/group/comp....ba85f541175295

    --
    Regards,
    Troels Arvin <troels@arvin.d k>

    Comment

    • Frank Swarbrick

      #3
      Re: TRUNCATE stored procedure

      >>On 5/22/2008 at 3:51 PM, in message <g14psm$d6b$1@n ews.net.uni-c.dk>,
      Troels Arvin<troels@ar vin.dkwrote:
      Frank Swarbrick wrote:
      >It uses "IMPORT FROM NUL OF DEL REPLACE INTO ...", where other examples
      >of this type of thing seem to use LOAD instead of IMPORT.
      >
      The IMPORT-based method
      - requires less privileges than other methods
      - if fully recoverable
      >
      See also

      cc36736aa9b81c6 c/a0ba85f54117529 5
      Does this mean that IMPORT does logging?
      If so, why would this method be preferred over just a plain DELETE FROM
      <tablestatement ?

      In the case I'm looking for it's simply for truncating a table for testing,
      so I can rerun the test and insert the data again. I assume in this case I
      would not care about it being recoverable.

      Frank


      Comment

      • Ian

        #4
        Re: TRUNCATE stored procedure

        Frank Swarbrick wrote:
        >>>On 5/22/2008 at 3:51 PM, in message <g14psm$d6b$1@n ews.net.uni-c.dk>,
        Troels Arvin<troels@ar vin.dkwrote:
        >Frank Swarbrick wrote:
        >>It uses "IMPORT FROM NUL OF DEL REPLACE INTO ...", where other examples
        >>of this type of thing seem to use LOAD instead of IMPORT.
        >The IMPORT-based method
        > - requires less privileges than other methods
        > - if fully recoverable
        >>
        >See also
        >http://groups.google.com/group/comp....se_frm/thread/
        >cc36736aa9b81c 6c/a0ba85f54117529 5
        >
        Does this mean that IMPORT does logging?
        If so, why would this method be preferred over just a plain DELETE FROM
        <tablestatement ?
        Yes, but it just logs a small record indicating that the table was
        replaced (truncated).

        Obviously this is much more efficient than logging each record that is
        deleted.

        In the case I'm looking for it's simply for truncating a table for testing,
        so I can rerun the test and insert the data again. I assume in this case I
        would not care about it being recoverable.
        That could certainly be the case.

        Remember, "recoverabl e" only applies if your database is enabled for
        archive logging.

        Comment

        Working...