Unexpected table grow .

  • Hi, everyone:

    i met a very wierd problem this morning. i have a SSIS package, which clean a table, then run a SP to insert records to this table. the SSIS package will run every 1 min. this morning, i check the database, there are only 9 records in the table, but the size of table was 7GB!

    after I drop the table and re-create it, let the SSIS package insert records again. the size of table dropped to 1 KB.

    the database recovery mode is 'simple'.

    can anyone tell me what's wrong here?

    _______________________________________________________________

  • Does your table have a clustered index?

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • You say "clean a table." What does that mean? Are you deleting records? How many? Please post DDL for the table and DML for the job as suggested by Jeff Moden's article in my signature.

    Jared
    CE - Microsoft

  • thank you , guys:

    1. there is no index on this table. because it has been deleted\inserted all the time, and only about total 10 records there, i didn't see any reason to place an index on this table.

    2. 'clean table'. The ssis has a 'foreach loop container', which will delete from table by PO_No, one row each time; and then run a SP by PO_No, insert a new row; untill all row has been refreshed. again, total about 10 rows.

    table definition:

    CREATE TABLE [dbo].[PO_JDE](

    [PO_No] [int] NOT NULL,

    [PO_Amount] [money] NOT NULL,

    [Vendor_ID] [int] NOT NULL,

    [Document_Type_ID] [smallint] NOT NULL,

    [Business_Unit] [varchar](7) NOT NULL,

    [Budget_Hold_Ind] [char](1) NOT NULL,

    [Budgeted_Ind] [char](1) NOT NULL,

    [PO_Status_ID] [smallint] NOT NULL,

    [User_Name] [varchar](10) NOT NULL

    ) ON [PRIMARY]

    _______________________________________________________________

  • michael wang-201906 (3/20/2012)


    thank you , guys:

    1. there is no index on this table. because it has been deleted\inserted all the time, and only about total 10 records there, i didn't see any reason to place an index on this table.

    2. 'clean table'. The ssis has a 'foreach loop container', which will delete from table by PO_No, one row each time; and then run a SP by PO_No, insert a new row; untill all row has been refreshed. again, total about 10 rows.

    table definition:

    CREATE TABLE [dbo].[PO_JDE](

    [PO_No] [int] NOT NULL,

    [PO_Amount] [money] NOT NULL,

    [Vendor_ID] [int] NOT NULL,

    [Document_Type_ID] [smallint] NOT NULL,

    [Business_Unit] [varchar](7) NOT NULL,

    [Budget_Hold_Ind] [char](1) NOT NULL,

    [Budgeted_Ind] [char](1) NOT NULL,

    [PO_Status_ID] [smallint] NOT NULL,

    [User_Name] [varchar](10) NOT NULL

    ) ON [PRIMARY]

    And it runs every minute? So, 10 rows of data get deleted and the rewritten every minute? I'm really confused... Can you describe why this is being done?

    Jared
    CE - Microsoft

  • michael wang-201906 (3/20/2012)


    Hi, everyone:

    i met a very wierd problem this morning. i have a SSIS package, which clean a table, then run a SP to insert records to this table. the SSIS package will run every 1 min. this morning, i check the database, there are only 9 records in the table, but the size of table was 7GB!

    after I drop the table and re-create it, let the SSIS package insert records again. the size of table dropped to 1 KB.

    the database recovery mode is 'simple'.

    can anyone tell me what's wrong here?

    Deleting from a table won't necessarily cause space allocated to a table to decrease. In order to do that, you have to do one of two things. Either drop the table and rebuild it or do a rebuild on the clustered index. Since your table is a heap, you can either use the drop method or you'll need to add a clustered index.

    {EDIT}. You could also use TRUNCATE to clear the table at the end of the run. Truncate deallocates rows from the table.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • you are right, 10 rows been deleted insert every min.

    the reason I do so is, i put all 'open' PO into this temp table, keep updating the status\details of each PO from 2 data source every min; when the PO has been 'closed', it will be removed from temp table.

    _______________________________________________________________

  • ...

    Since your table is a heap, you can either use the drop method or you'll need to add a clustered index.

    ...

    You could also use TRUNCATE to clear the table at the end of the run. Truncate deallocates rows from the table.

    That's why the question about clustered index...

    TRUNCATE should help in case of "heap" tables to reclaim the space...

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • michael wang-201906 (3/20/2012)


    you are right, 10 rows been deleted insert every min.

    the reason I do so is, i put all 'open' PO into this temp table, keep updating the status\details of each PO from 2 data source every min; when the PO has been 'closed', it will be removed from temp table.

    Why not just update it in the table where the data is permanently stored? There could be a good reason, but I find that these types of tables are rarely used for a good reason.

    Jared
    CE - Microsoft

  • the data source is on DB2, which i don't want to modify, that's why i download them to SQL by SSIS.

    thank you everyone, i will try to create an clustered index to see if it help.

    _______________________________________________________________

  • michael wang-201906 (3/20/2012)


    the data source is on DB2, which i don't want to modify, that's why i download them to SQL by SSIS.

    thank you everyone, i will try to create an clustered index to see if it help.

    Just creating the clustered index won't do it by itself. You need a scheduled job or some other code that will rebuild the clustered index (and, thus, the data itself) every once in a while.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply