October 20, 2011 at 1:10 am
In delete and truncate which one really free the memory after running?
Thanks
October 20, 2011 at 1:40 am
Not sure what you are asking. Are you worried about memory or disk or what?
CEWII
October 20, 2011 at 2:43 am
Thanks Eliott,
I just want to know if I run a delete and trucate to remove a row from the table(Suppose table has only single row) then which one actully free the memory(Memory means not Ram but Hard disk drive) for use of other process.
Will both commands free the memory if yes then If I am running a delete command for 100 rows in which total table rows has 1000.then in this case will the deleted rows memory(Memory means not Ram but Hard disk drive) be free for other processess.
Thanks
October 20, 2011 at 2:57 am
please correct me if i am wrong on this sql guru's
when a row is deleted it is actually marked for deletion, then the internal clean up tasks comes along and removes the row from the data pages.
as a delete is not a deallocation of pages, the page(s) to which the rows have been deleted from are still assigned to that particular table and therefore are ready for new rows to be added into the table
a truncate is a deallocation of pages meaning when something writes to the table again a new data page has to be aquired
in both cases, the only thing that happens is white space in a page / data file is created
the database is not shrunk it is left as it is, therefore the "white space" is not available to other processes.
if you want to created more disk space then you will need to do something like dbcc shrinkfile or shrinkdatabase
October 20, 2011 at 3:10 am
Thanks anthony,
For such idea...
Thanks
October 20, 2011 at 3:14 am
also memory = RAM, storage = hard drive space, to prevent any confusion for future posts
October 20, 2011 at 5:24 am
You also have to take into account what happens with the transaction log. When you delete 1000 rows, they're recorded in the log that way, increasing the amount of information logged. When you truncate a table, that single operation is logged, causing less impact there.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 20, 2011 at 9:31 am
I find I can read your question 2 different ways.
The first is if I delete or truncate when do I get space back in the filesystem, the answer is that without additional work probably never.
The second is if I delete or truncate a table when can that space be reused, and the answer is basically right away.
The truncate is a deallocation of pages, which is considered a minimally logged operation, whereas a delete is a fully logged operation.
CEWII
October 20, 2011 at 10:21 am
truncate deallocates the pages.
delete flags rows as deleted, ghost cleanup task runs periodically in the background, and removes the rows from the page. If the page is then completely empty, ghost cleanup task will deallocate it.
October 20, 2011 at 12:11 pm
anthony.green (10/20/2011)
please correct me if i am wrong on this sql guru'swhen a row is deleted it is actually marked for deletion, then the internal clean up tasks comes along and removes the row from the data pages.
Exactly! Here is a link that goes into more detail if anyone is interested: http://sqlserverpedia.com/blog/sql-server-bloggers/fact-checking-ghost-cleanup-part-i/
Thanks,
Jared
Jared
CE - Microsoft
October 22, 2011 at 1:43 am
SHRINKFILE huh
Use this only when absolutely necessary. You might end up with 1TB defragmetated discs very soon with performance issues instead.
Be careful
October 28, 2011 at 2:45 am
Sure...Thanks...
Thanks
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply