Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Delete records without logging Expand / Collapse
Author
Message
Posted Monday, June 17, 2013 1:15 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 9, 2013 1:15 AM
Points: 15, Visits: 167
Deal all,

we have a database AA in SQL Server,while inserting the records to table DB log file size are growing same scenario happening while deleting the records.we dont want log growing for deleting the records without affecting DB Mirror,how to handle this ONE?

Please help me on this?
Post #1464007
Posted Monday, June 17, 2013 1:36 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 7:19 AM
Points: 2,112, Visits: 5,477
You can't do any and modification in the database without logging. Logging is essential for the database. Without it the server won't be able to rollback any statement. If you don't want the log to grow so much you can do the fallowing things:
If you delete the whole table and there is no replication and other tables don't reference your table with a foreign key, then you can truncate the table instead of running the delete statement. This will still be logged, but it will log the modification in the table's pages allocation and not every record that was deleted.
If you delete many records, you should delete it in chunks and not all the records in one statement. If your database is in full recovery or bulk logged model you can do logs backup between the chunks (not between each one of them, but after each X chunks. You'll have to work out yourself when to do it). If the database is in simple recovery model, you don't have (and can't) do the log backup.

Adi


--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1464011
Posted Monday, June 17, 2013 2:39 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 9, 2013 1:15 AM
Points: 15, Visits: 167
thanks
Post #1464028
Posted Monday, June 17, 2013 3:41 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, June 24, 2014 6:38 PM
Points: 1,371, Visits: 1,560
There is nothing called "No Logging" in SQL Server...there is something called "Minimal Logging". This can be achieved by using table locking hints.

DELETE FROM TableName  with (TABLOCK) WHERE id > 100;

For more details, refer this link:
http://blogs.msdn.com/b/sqlserverstorageengine/archive/2008/03/06/minimal-logging-changes-in-sql-server-2008-part-1.aspx


~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1464045
Posted Monday, June 17, 2013 3:44 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 9, 2013 1:15 AM
Points: 15, Visits: 167
thanks lokesh.its very help to us...
Post #1464046
Posted Monday, June 17, 2013 4:19 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 39,898, Visits: 36,243
Lokesh Vij (6/17/2013)
There is nothing called "No Logging" in SQL Server...there is something called "Minimal Logging". This can be achieved by using table locking hints.

DELETE FROM TableName  with (TABLOCK) WHERE id > 100;




Err, no.
Minimal logging is for inserts, not deletes. You can't minimally log deletes.

The blog describes how to use TABLOCK on an insert to get minimal logging in bulk-logged and simple recovery.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #1464058
Posted Monday, June 17, 2013 4:22 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 39,898, Visits: 36,243
balamurugan.devadas (6/17/2013)
we dont want log growing for deleting the records without affecting DB Mirror,how to handle this ONE?


Minimal logging is not a possibility, because deletes can't be minimally logged and even if they could mirroring requires full recovery model.

The usual method is to delete in chunks and do transaction log backups between each chunk. It'll still use the same amount of log but the log backups mark the log reusable between each delete chunk.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #1464059
Posted Monday, June 17, 2013 4:28 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 8:46 PM
Points: 35,218, Visits: 31,676
Lokesh Vij (6/17/2013)
There is nothing called "No Logging" in SQL Server...there is something called "Minimal Logging". This can be achieved by using table locking hints.

DELETE FROM TableName  with (TABLOCK) WHERE id > 100;

For more details, refer this link:
http://blogs.msdn.com/b/sqlserverstorageengine/archive/2008/03/06/minimal-logging-changes-in-sql-server-2008-part-1.aspx


I agree with Gail. You cannot achieve minimal logging for DELETEs. It also usually takes a whole lot more than just using WITH(TABLOCK) to achieve minimal logging on inserts, as well. There's a whole set of rules in Books Online for what is necessary to achieve minimal logging.

As Adi pointed out above, if you want to delete the entire contents of a table and it meets the rules he stated, then you could use TRUNCATE instead of DELETE and that will be minimally logged.


--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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1464063
Posted Monday, June 17, 2013 4:45 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 39,898, Visits: 36,243
Jeff Moden (6/17/2013)
then you could use TRUNCATE instead of DELETE and that will be minimally logged.


Technically truncate is fully logged. It just logs the page deallocations like a drop table does rather than the rows as delete does.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #1464071
Posted Monday, June 17, 2013 4:52 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, June 24, 2014 6:38 PM
Points: 1,371, Visits: 1,560
GilaMonster (6/17/2013)
Lokesh Vij (6/17/2013)
There is nothing called "No Logging" in SQL Server...there is something called "Minimal Logging". This can be achieved by using table locking hints.

DELETE FROM TableName  with (TABLOCK) WHERE id > 100;




Err, no.
Minimal logging is for inserts, not deletes. You can't minimally log deletes.

The blog describes how to use TABLOCK on an insert to get minimal logging in bulk-logged and simple recovery.


Thanks Gail for correcting me.


~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1464075
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse