How we dealocate the memory of a row

  • How we dealocate the memory of a row in a table in sql 2008 R2. please show the query if exist.

  • There is not normally a need to. What exactly makes you think you should need to do this - especially fo rone row?

    Normally the space will be reused a new rows are added/deleted etc. Under rare situations such as a heap table and all new data being added then huge deletes of old data you can end up with a large number of empty pages. These will be used if new rows are added or you can create a clustered index on the table to restructure it.

    Mike John

  • Can you explain further what you want to do?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • chaudharydpk0 (1/10/2012)


    How we dealocate the memory of a row in a table in sql 2008 R2. please show the query if exist.

    You cannot do this. But like Gail I want to know WHY you THINK you want to do this. There is likely something else at play here that we could address for you.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • chaudharydpk0 (1/10/2012)


    How we dealocate the memory of a row in a table in sql 2008 R2. please show the query if exist.

    OK, I'll take a stab at interpreting your request literally. When you ask how to "dealocating the memory of a row", perhaps you're asking how to deallocate memory from the buffer pool where SQL Server caches pages. SQL Server caches data at the page level, not the row level.

    DBCC DROPCLEANBUFFERS

    http://msdn.microsoft.com/en-us/library/ms187762.aspx

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

  • Sir, actually i delete 5000 rows in my table in sql 2008 r2 but after that the table size in unchanged.

  • Sir, actually i deleted 5000 rows in my table in sql 2008 r2 but after that the table size in unchanged. I daily need to delete thousand's record in a table and in next day fill up with new data either same size or less or more size.

  • chaudharydpk0 (1/12/2012)


    Sir, actually i deleted 5000 rows in my table in sql 2008 r2 but after that the table size in unchanged. I daily need to delete thousand's record in a table and in next day fill up with new data either same size or less or more size.

    How did you check the table size?

    Are are talking about datable files (.mdf/.ndf/.ldf) by any chance?

  • Sounds like you are expecting the data files to automaticallly shrink, which does not happen unless explicitly set at the database level or requested on an ad-hoc bases.

    Try DBCC SHRINKFILE

    Use the TRUNCATEONLY option first, this should shrink the file providing the data you are deleting was more or less the last quantity of data that was inserted. Truncate will remove the free space from the end of the file and is instant, a normal shrink to a specific size will involve shuffle the data pages and this is very resource / time consuming.

    For more info:

    http://msdn.microsoft.com/en-us/library/ms189493.aspx

    Rob

  • chaudharydpk0 (1/12/2012)


    Sir, actually i delete 5000 rows in my table in sql 2008 r2 but after that the table size in unchanged.

    Nothing unusual there. The deleted rows are scattered throughout the table. Rebuild your clustered index and the table size will drop. Avoid shrink unless you absolutely must release the space to the OS. It's better to leave free space within the database for future use. Also, unless you first rebuild the index, there will be no free pages for shrink to release as the free space will be spread throughout the table.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • roasdasdb 89asdasdasd013 (1/12/2012)


    Sounds like you are expecting the data files to automaticallly shrink, which does not happen unless explicitly set at the database level or requested on an ad-hoc bases.

    Try DBCC SHRINKFILE

    Use the TRUNCATEONLY option first, this should shrink the file providing the data you are deleting was more or less the last quantity of data that was inserted. Truncate will remove the free space from the end of the file and is instant, a normal shrink to a specific size will involve shuffle the data pages and this is very resource / time consuming.

    For more info:

    http://msdn.microsoft.com/en-us/library/ms189493.aspx

    Rob

    DO NOT DO THIS.

    And stop worrying about the data space for 5000 rows. You are gonna put more data into the database, and SQL Server will be able to reuse the space on those data pages.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

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

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