DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: truncate table

  1. #1
    Join Date
    Nov 2000
    Posts
    169

    Angry

    Is there an easy way to truncate 10 tables with one command instead of typing
    "truncate table table_name;" 10 times?

  2. #2
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    no, you have to build a script then run the script

    like

    Code:
    spool truncate.sql
    select 'truncate table '||table_name||';'
    from user_tables
    where table_name in (blah blah blah);
    spool off
    
    @truncate.sql

  3. #3
    Join Date
    Oct 2000
    Location
    Saskatoon, SK, Canada
    Posts
    3,925
    Syntax correction:

    Originally posted by pando
    no, you have to build a script then run the script

    like

    Code:
    spool truncate.sql
    select 'truncate table '||table_name||';'
    from user_tables
    where table_name in (blah blah blah);
    spool off
    
    @truncate.sql
    spool truncate.sql
    select 'truncate table '||table_name||';'
    from user_tables
    where table_name in ( 'blah', 'blah', 'blah');
    spool off

    @truncate.sql


    Too many blahs. BLAH

    Sam
    Thanx
    Sam



    Life is a journey, not a destination!


  4. #4
    Join Date
    Jun 2001
    Location
    Helsinki. Finland
    Posts
    3,938
    I use a dynamic script which truncates all tables of a schema (which comes as a parameter). I would advise you to try to make such a script (and thus practice your dynamic SQL skills :-))


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width