Interrupted TRUNCATE TABLE command

Hello,
I've made very dangerous mistake today: TRUNCATE TABLE on production database. :-(
But in several seconds (2 or 3), I managed to break the operation (Before the execution ended).
It was quite a big table, now (after the accident) there are more then 32 million records.
We need to know, are there any records deleted?
We have no proper backup, to compare the records with it.
And I could not find any in-depth description of how TRUNCATE works.
Please can you:
1. Tell, about any method to check if there are deleted records?
2. Link, to any resource, where I can read in details, about how TRUNCATE TABLE works.
Thanks, in advance, for help

My understanding is that the TRUNCATE TABLE table statement is atomic. It either fails or succeeds. Truncates all rows or no rows at all. Therefore if you interrupt a TRUNCATE TABLE statement your table should remain in its original state.
This can be shown below:
SQL > CREATE TABLE TEST AS SELECT * FROM ALL_OBJECTS;
Table created.
SQL > INSERT INTO TEST SELECT * FROM TEST;
12421 rows created.
SQL > INSERT INTO TEST SELECT * FROM TEST;
24842 rows created.
SQL > INSERT INTO TEST SELECT * FROM TEST;
49684 rows created.
SQL > INSERT INTO TEST SELECT * FROM TEST;
99368 rows created.
SQL > INSERT INTO TEST SELECT * FROM TEST;
198736 rows created.
SQL > INSERT INTO TEST SELECT * FROM TEST;
397472 rows created.
SQL > INSERT INTO TEST SELECT * FROM TEST;
794944 rows created.
SQL > INSERT INTO TEST SELECT * FROM TEST;
1589888 rows created.
SQL > SELECT COUNT(*) FROM TEST;
  COUNT(*)
   3179776
SQL > TRUNCATE TABLE TEST;
^C
H:\>sqlplus /@testdb
SQL*Plus: Release 10.2.0.4.0 - Production on Mon Aug 3 08:20:11 2009
Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
Enter password:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL > SELECT COUNT(*) FROM TEST;
  COUNT(*)
   3179776HTH!

Similar Messages

  • Reg: Truncate table command in Stored Procedures

    Hi All,
    I wrote one procedure in which i used 'Truncate Table command' and while compiling I am getting an error. I searched on google but again many queries has been asked there but no suitable solution is there. So please help me in understanding this matter.I will be really obliged of you.
    Gursimran Singh

    Hi thanks for your reply. The error I am getting is here
    PLS-00103: Encountered the symbol "TABLE" when expecting one of the following:
    := . ( @ % ;
    The symbol ":= was inserted before "TABLE" to continue.
    I appreciate your step to use 'execute immediate 'truncate table table_name';. but the thing is that the system is not allowing my to use TRUNCATE than how come i use the above expression.
    Second thing is that there is no error in syntax, everything is fit and fine.
    Gursimran

  • Internal Behaviour of Truncate Table Command in Oracle Database

    Hi,
    Can anyone let me know the internal behaviour of Truncate Table Command in Oracle Database?
    Thanks,
    Harshad.

    Hi Tuhinshoor,
    I know the functioning of Truncate Command.
    But, I needed to know whether it drops the table before recreating it, maintaining all the indexes and constraints intact??
    Thanks,
    Harshad.

  • TRUNCATE TABLE NOT WORKING AFTER DROPPING CONSTRAINTS

    Hi,
    I have a table with a foreign key constraint. I know you can't truncate tables when there are foreign key constraints. So I drop the constraints before running the TRUNCATE TABLE command. But SQL Server is still stating there are foreign key constraints
    even after they have just been dropped.
    When I use SQL Server Management Studio to generate a drop & create script on this table or any other table with an FK consttaint, the generated script fails stating that there are still foreign key constraints??
    I have the same problem for every table that has FK constraints, for those without FK, TRUNCATE table works without issues.
    The end goal is to reset the identity value of the primary key. Since DBCC does not work on Azure, TRUNCATE TABLE is the only way left, especially if you can't even drop and recreate tables with FK constraints.
    What am I missing here?
    Peter

    Hi,
    Thanks for posting here.
    TRUNCATE TABLE is similar to the DELETE statement with no WHERE clause; however, TRUNCATE TABLE is faster and uses fewer system and transaction log resources.
    TRUNCATE TABLE removes all rows from a table, but the table structure and its columns, constraints, indexes, and so on remain. To remove the table definition in addition to its data, use the DROP TABLE statement.
    If the table contains an identity column, the counter for that column is reset to the seed value defined for the column. If no seed was defined, the default value 1 is used. To retain the identity counter, use DELETE instead.
    Restrictions
    You cannot use TRUNCATE TABLE on tables that:
    •Are referenced by a FOREIGN KEY constraint. (You can truncate a table that has a foreign key that references itself.)
    •Participate in an indexed view.
    •Are published by using transactional replication or merge replication.
    For tables with one or more of these characteristics, use the DELETE statement instead.
    TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions. For more information, see CREATE TRIGGER (Transact-SQL).
    Truncating Large Tables
    Microsoft SQL Server has the ability to drop or truncate tables that have more than 128 extents without holding simultaneous locks on all the extents required for the drop.
    Permissions--------------------------------------------------------------------------------
     The minimum permission required is ALTER on table_name. TRUNCATE TABLE permissions default to the table owner, members of the sysadmin fixed server role, and the db_owner and db_ddladmin fixed database roles, and are not transferable. However, you
    can incorporate the TRUNCATE TABLE statement within a module, such as a stored procedure, and grant appropriate permissions to the module using the EXECUTE AS clause.
    You cannot truncate a table which has an FK constraint on it.
    Typically my process for this is:
    Drop the constraints
    Trunc the table
    Recreate the constraints.
    Hope this helps you.
    Girish Prajwal

  • ORA-01502: Index or Partition is in unusable status. while truncating table

    Hi All,
    One of our Devlopers compalined that he is getting ORA-01502 : Index or partition is unusable status while truncating the a table in our Dataware house production database. He is using the following commands.
    Alter index <index_name> unusable;
    Truncate table <table_name> ;
    He is running a scripts to truncate each table and ecah time he is passing the table name as an input parameter to script. He is using same method to truncate four tables each having a BITMAP and a REGULAR index. For two tables every thing is working fine, but for other two tables the he is getting ORA-01502 for BITMAP indexes. It a weekly process and every week he is getting the same issue. I checkd the Index status, they are in valid status only.
    For a work around I have created a table with BITMAP and regular index in our dev database. made the indexes unusable, checked their status. I truncated the table. Importent thing here is the Indexes are becoming vaild when I truncate the table.
    I suspect that my devloper's Indexes were already in unusable status (before he use the command ALTER INDEX), when he truncated the table, oracle trying to validate the index and throwing the error ORA-01502 because the Indexes are in unusabel statsu for a while.
    I tried searching for the mechanism of truncate table command and its effect on Indexes. But I did not find any luck, no one is speaking about index when truncating the table. Can any one please help me????
    Sorry for lengthy post. Any help is greatly appriciated and I thank every one in advance.

    DDL for Indexes getting ORA-01502 error
    CREATE BITMAP INDEX DWHMGR.ACT_TXN_LN_STG_01_XN3 ON DWHMGR.ACCT_TXN_LINE_TERM_BAL_STG_01 (TERM_BAL_CD ASC) TABLESPACE "BALFD_INX_04" NOLOGGING PCTFREE 1 INITRANS 2 MAXTRANS 255 STORAGE
    ( INITIAL 8M NEXT 8M MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 BUFFER_POOL DEFAULT );
    CREATE BITMAP INDEX DWHMGR.ACCT_TERM_BAL_STG_01_XN3 ON DWHMGR.ACCT_TERM_BAL_STG_01 TERM_BAL_CD ASC) TABLESPACE "BALFD_INX_04" NOLOGGING PCTFREE 1 INITRANS 2 MAXTRANS 255 STORAGE
    ( INITIAL 8M NEXT 8M MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 BUFFER_POOL DEFAULT );
    Indexes that have no issues.
    CREATE INDEX DWHMGR.ACCT_TERM_BAL_STG_01_XN2 ON DWHMGR.ACCT_TERM_BAL_STG_01 (ACCT_REF_NB ASC) TABLESPACE "BALFD_INX_04" NOLOGGING PCTFREE 1 INITRANS 2 MAXTRANS 255 STORAGE (INITIAL 8M
    NEXT 8M MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 BUFFER_POOL DEFAULT );
    CREATE BITMAP INDEX DWHMGR.ACCT_PRC_STG_01_XN1 ON DWHMGR.ACCT_PRC_STG_01 (ACCT_ORG_CD ASC) TABLESPACE "BALFD_INX_04" NOLOGGING PCTFREE 1 INITRANS 2 MAXTRANS 255 STORAGE ( INITIAL 8M
    NEXT 8M MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 BUFFER_POOL DEFAULT );
    Please look at the DDL of the indexes and let me know if you need any other information.

  • Truncate table lock issue

    Hi,
        In my SQL2000 stored procedure, there are 9 truncate table commands.
         But the the stored procedure is take above 15 minutes to execute.
         In this stored procedure, truncate table command has no problem.
         But an insert query into that table is very slow.
         In the insert query, select some views output and insert into the table. But these select output is very slow.
         I search some forums. They said that lock problem for the object. Query execution delayed for a exclusively accessed object.
        How can I remove the lock for my strored procedure running faster ? 

    Here are the bad news: you need to have some understanding of indexing to get some results out of it. But since we don't know anything about your queries, we cannot really give much better advice. What we can say is that TRUNACTE TABLE has nothing to
    do with it. Probably not locking either. Locking would come from concurrent activity in the database. Is there any?
    Normally, we ask people to submit the code they have problem with. In this case we would also need see the view definitions. (Else we would still be in the dark.) And if the views are built on views, we need to see these as well. This may result in more
    code that is practic to handle here, but I leave that up to you. As a hint: in the next step we are much likely to ask for the table and index definitions.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Shrink table and Truncate/delete command

    Friends ,
    Regarding truncate cmmand we know ,
    "Truncate table removes all rows from a table, but the table structure and its columns, constraints, indexes etc., remains as it is."
    That means the table's data are deleted but the block is still not free .Blocks are still use the information of table's structue & others . In this case , if I shrink that table then what happen ? Are these blocks are going to be free or still contain the structure and its columns, constraints, indexes informaton ? Blocks becomes unused or used ?
    Waiting for reply ... ...

    Shippon,
    Trucate table <table> with 2 options
    1. reuse storage : leaces the space currently used by deleted rows: Leaves the HWM to where it is
    2. drop stroage: deallocated the space currently used by deleted rows: Resets the HWM to zero
    Are these blocks are going to be free or still contain the structure and its columns, constraints, indexes informaton ? Blocks becomes unused or used ?
    The  cleaned up blocks contains data and not the structure and indexes information. Truncate is just dropping data not structure (metadata). Blocks will be reused by my_objects again if "REUSE" option used, and if "DROP" option used, then blocks will be available to all the objects on residing on that tablespace.
    _*Example*_
    TABLE_NAME                       NUM_ROWS     BLOCKS INITIAL_EXTENT EMPTY_BLOCKS
    MY_OBJECTS                          84018        625          81920           15
    1 row selected.
    Truncate table my_object reuse storage;
    TABLE_NAME                       NUM_ROWS     BLOCKS INITIAL_EXTENT   EMPTY_BLOCKS
    MY_OBJECTS                              0                 0          81920                         640
    1 row selected.
    Truncate table my_object drop storage;
    TABLE_NAME                       NUM_ROWS     BLOCKS INITIAL_EXTENT     EMPTY_BLOCKS
    MY_OBJECTS                              0                 0          81920                             8
    1 row selected.Regards

  • What is the recommended way to truncate tables in ODI?

    I want to create a separate step to truncate the result tables, before the start of the actual job. What is the recommended way of doing this?
    I am currently putting the truncate statements in the ODI procedure, but that has a lot of typing. Is there a odi command in the toolbox that I can use?
    Thanks.

    Ok,
    If the table will be loaded by interfaces, you have the "Truncate" option at the IKM's, just change it to "Yes".
    If you need to Truncate but they won't be loaded by Interfaces a possible way is:
    - requirements: it will be necessary to have some common "string" at tables names.
    1) create a procedure
    2) create an step
    3) at source tab put:
    Select table_name from user_tables where table_name in '%THE_STRING%'
    4) at target tab put:
    Truncate table #table_name
    If you don't have a common "string" you, instead, can create a table with all table names that you need to truncate and change the select command at 3).
    Does it help you?
    Message was edited by:
    Cezar_Santos

  • TRUNCATE TABLE  does not work in procedure

    Hi Friends,
    I create a procedure that have a command TRUNCATE TABLE errdbg;
    It use to record data processing information. It iworks in SQLPLUS by manually.
    I put it in procedure and get message as
    Warning: Package Body created with compilation errors.
    SQL> show error;
    Errors for PACKAGE BODY DATALOAD:
    LINE/COL ERROR
    172/10 PLS-00103: Encountered the symbol "TABLE" when expecting one of
    the following:
    := . ( @ % ;
    The symbol ":= was inserted before "TABLE" to continue.
    How to use TRUNCATE command in procedure?
    I can use delete. but it is not good for table space resused based on book.
    Thanks
    JIm

    You can't use DDL in pl/sql unless you use it with execute immediate
    e.g.,
    execute immediate 'truncate table errdbg' ;

  • Truncate table will delete the corresponding LOB segment of table or not ?

    Hi All,
    I have few table with LOB segments, if i fire the truncate table on those table will it purge the LOB segment as well ?
    Approximately how much time will take to truncate 100gb LOB segments.
    Thanks

    903787 wrote:
    Hi ,
    1.Truncate will delete the LOB segment or not ?It won't delete the LOB segments but it should release most of the allocated space.
    >
    2.To reclaim space we need to run the below command, is it correct ?
    ALTER TABLE <table_name> MODIFY LOB (LOB_COLUMN) (SHRINK SPACE);
    Should not be needed in 11.2:
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for 32-bit Windows: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    SQL> select count(*) from user_segments;
      COUNT(*)
             0
    SQL>
    SQL> create table t(x clob);
    Table created.
    SQL> select segment_name, segment_type, bytes
      2  from user_segments;
    SEGMENT_NAME                             SEGMENT_TYPE            BYTES
    T                                        TABLE                   65536
    SYS_IL0000030908C00001$$                 LOBINDEX                65536
    SYS_LOB0000030908C00001$$                LOBSEGMENT              65536
    SQL>
    SQL> insert into t select lpad(segment_name,8192) from dba_segments;
    6312 rows created.
    SQL> commit;
    Commit complete.
    SQL>
    SQL> select segment_name, segment_type, bytes
      2  from user_segments;
    SEGMENT_NAME                             SEGMENT_TYPE            BYTES
    T                                        TABLE                  393216
    SYS_IL0000030908C00001$$                 LOBINDEX                65536
    SYS_LOB0000030908C00001$$                LOBSEGMENT           53477376
    SQL>
    SQL> truncate table t;
    Table truncated.
    SQL>
    SQL> select segment_name, segment_type, bytes
      2  from user_segments;
    SEGMENT_NAME                             SEGMENT_TYPE            BYTES
    T                                        TABLE                   65536
    SYS_IL0000030908C00001$$                 LOBINDEX                65536
    SYS_LOB0000030908C00001$$                LOBSEGMENT              65536
    SQL>
    SQL> alter table t modify lob(x) (shrink space);
    Table altered.
    SQL>
    SQL> select segment_name, segment_type, bytes
      2  from user_segments;
    SEGMENT_NAME                             SEGMENT_TYPE            BYTES
    T                                        TABLE                   65536
    SYS_IL0000030908C00001$$                 LOBINDEX                65536
    SYS_LOB0000030908C00001$$                LOBSEGMENT              65536
    SQL>

  • Error when trying to truncate table from within PL/SQL

    Hello.....
    Does anyone know why I get an error when trying to execute the following command from within PL/SQL?
    truncate table event;
    The error is as follows:
    ORA-06550: line 20, column 14:
    PLS-00103: Encountered the symbol "TABLE" when expecting one of the following:
    := . ( @ % ;
    The symbol ":= was inserted before "TABLE" to continue.

    And as a DDL, it does a COMMIT just before it runs. Whether you want a COMMIT or not.
    And with all the locking and serialization issues associated with a DDL.

  • Unable to truncate table from plsql

    i want to collect stats as my query runs.
    i cannot do it from plsql
    declare
      -- Local variables here
      i integer;
    begin
      -- Test statements here
       SET AUTOTRACE ON;
    truncate  table plan_table;
    end;how do i do it.

    Hi,
    TRUNCATE TABLE is not a PL/SQL command; it's a SQL command.
    To run a purely SQL command in PL/SQL, use EXECUTE IMMEDIATE.
    SET AUTOTRACE isn't a PL/SQL command either; it's a SQL*Plus command, and I don't know of any way to run it except from the SQL*Plus command prompt.
    I think this is what you need to do:
    SET AUTOTRACE ON;
    declare
      -- Local variables here
      i integer;
    begin
      -- Test statements here
        EXECUTE IMMEDIATE 'truncate  table plan_table';
    end;

  • Flashback and truncate table in 11gR2

    Hi,
    From what I can gather, flashback database is the only flashback operation that can undo a table truncate. A truncate table operation cannot be rolled back, because it does not produce the undo data necessary for undo based flashback operations like Flashback query, version, transaction/backup and table.
    Is this assessment correct?
    Thanks.

    Pal wrote:
    Thanks for reply. I hope it's ok to add a couple more related questions:
    SQL> select current_scn from v$database;
    1088080
    SQL> connect hr/hr
    SQL> truncate table test_data;
    SQL> select * from test_data as of SCN 1088080;
    ORA-01466: unable to read data - table definition has changedYes, that's correct Pal. The reason is that with any DDL , the structure/definition of the table would be changed and Flashback Query won't be allowed on such table.
    I cannot use Flashback Query, however, just reading http://ocpdba.wordpress.com/2009/10/19/reversing-the-effect-of-a-truncate-table-in-oracle-11gr2 which demonstrates how to use Flashback Data Archive and Flashback Query to reverse a table truncate operation.
    Why does Flashback Data Archive allow me to use Flashback Query past DDL operations?Please see,
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17125/adfns_flashback.htm#BJFJHDAG
    Actually, even with the Flasback data archive too, you can't do anything if the table structure is modified by a command whose effect it can't tolerate. In 11.2, what is given is that you can dissociate your table from the Flashback DAta archive using the package DBMS_FLASHBACK_ARCHIVE.DISASSOCIATE_FBA , do the changes on both target and archive table and then reassociate . Oracle does makes a note in this operation that assume no aboslute guarantee in the data's accuracy if you would do this procedure.
    If I do not have Flashback Data Archive enabled on a table, how can I determine the SCN to undo a truncate table using Flashback database or TSPITR?You would need to mine the logfile using the logminer .
    HTH
    Aman....

  • Full Load: Error while executing :TRUNCATE TABLE: S_ETL_PARAM

    Hi All,
    We are using Bi Apps 7.9.6.1. Full Load was running fine. But Now we are facing a problem with truncating a table "S_ETL_PARAM".
    I have restart informatica Server And also DAC Srever. But still I am getting the same in the DAC Log as, *"NOMALY INFO::: Error while executing : TRUNCATE TABLE:S_ETL_PARAM*
    *MESSAGE:::com.siebel.etl.database.IllegalSQLQueryException: DBConnection_OLTP:SIEBTRUN ('siebel.S_ETL_PARAM')*
    *Values :*
    *Null Map*
    *EXCEPTION CLASS::: java.lang.Exception"*
    Any Suggestion.....
    Thanks in Advance,
    Deepak

    are you trying to run incremental load when you get this truncate error? can you re-run full load and see that still runs ok? pls also check your DW side database logs like alert lor any DB level issue. such errors do not throw friendly messages in DAC/Informatica side.

  • Release of space after delete/truncate table

    Hello,
    How does release of space after delete/truncate table works? Is the space used before deletion released once delete is complete or not? Will I see the space occupied by deleted table as free in dba_segments or will I need to reorganize the table (drop and recreate again?). Reason why I am asking is that I can see table with 0 rows, but in dba_segment I can see it is occupying few gigabytes....
    Thank you

    Here is a little illustration for you;
    SQL> conn ogan/password
    Connected.
    SQL> create table ogan_deneme as select * from all_objects;
    Table created.
    SQL> select count(*) from ogan_deneme;
      COUNT(*)
        228470
    SQL> set line 1000
    SQL> set pagesize 1000
    SQL> select * from dba_segments where owner='OGAN';
    OWNER    SEGMENT_NAME        PARTITION_NAME           SEGMENT_TYPE       TABLESPACE_NAME                HEADER_FILE HEADER_BLOCK      BYTES     BLOCKS    EXTENTS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE  FREELISTS FREELIST_GROUPS RELATIVE_FNO BUFFER_
    OGAN      OGAN_DENEME          TABLE              SYSTEM                                 854       319981   *30408704*       *1856*         *44*          65536                       1  2147483645                       1               1          854 DEFAULT
    SQL> truncate table ogan_deneme;
    Table truncated.
    SQL> select * from dba_segments where owner='OGAN';
    OWNER    SEGMENT_NAME        PARTITION_NAME           SEGMENT_TYPE       TABLESPACE_NAME                HEADER_FILE HEADER_BLOCK      BYTES     BLOCKS    EXTENTS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE  FREELISTS FREELIST_GROUPS RELATIVE_FNO BUFFER_
    OGAN      OGAN_DENEME           TABLE              SYSTEM                                 854       319981      *65536*          *4*          *1*          65536                       1  2147483645                       1               1          854 DEFAULT
    SQL>Hope it Helps,
    Ogan

Maybe you are looking for

  • Can I transfer pictures from my pc to a new mac via an ipod touch?

    Hiya So my new macbook pro is on it's way and i was trying to think of some easier file sharing from my old pc to my new mac than a thumbdrive back and fourth x amount of times. My Pc's wireless card burnt out or something like that happened that mak

  • Data pump, Query "1=2" performance?

    Hi guys I am trying to export a schema using data pump however I need no data from a few of the tables since they are irrelevant but I'd still like to have the structure of the table itself along with any constraints and such. I thought of using the

  • Programmatically selecting Item in drop down

    I want to Programmatically select an item in a dropdown when the page is loaded. I am using the following code: <h:selectOneMenu binding="#{CatByLocTrend.predefinedQueryDropdown}" id="predefinedQueryDropdown" style="height: 21px; width: 133px; font-f

  • I touch doesn't connect to itunes

    My I touch does not appear in itunes under Devices.  I touch as the itunes logo with the USB cable icon.  I have held the home and the sleep/wake button together till the apple icon appeared, didn't change anything.  I have uninstalled and re-install

  • Immediate Access Error Installing Flash on Mac

    Attempting to install on a new macbook running OSX 10.5.4 I get an immediate "Error Creating File" error after the browser check. Safari is the only browser installed (Firefox was installed, I uninstalled it) I have run the "Fix Permissions" thing I