Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Delete sintax with where

Author  Topic 

mangalau
Starting Member

11 Posts

Posted - 2008-05-16 : 03:46:47
I have a large table and i wanna delete it but with where constraints
is there a way , that i can do that without filling the log file , it's frustrating to truncate every time that log

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2008-05-16 : 04:18:05
you don't want to do that because the reason for the constraint is so you don't get orphaned rows...

if you really want to do that... remove the constraint completely so you don't have to remove and recreate all the time you want to truncate

quote:
Originally posted by mangalau

I have a large table and i wanna delete it but with where constraints
is there a way , that i can do that without filling the log file , it's frustrating to truncate every time that log



--------------------
keeping it simple...
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-05-16 : 08:05:39
quote:
Originally posted by jen

you don't want to do that because the reason for the constraint is so you don't get orphaned rows...

if you really want to do that... remove the constraint completely so you don't have to remove and recreate all the time you want to truncate

quote:
Originally posted by mangalau

I have a large table and i wanna delete it but with where constraints
is there a way , that i can do that without filling the log file , it's frustrating to truncate every time that log



--------------------
keeping it simple...



...actually Jen, i don't think that's what the OP meant? I think what they're saying is that they want to do...

delete from table1
where col = 'x'

...but don't want it to fill the transaction log? i.e. they would use 'truncate table' except that they need to a 'where' clause

mangalau - is that what you mean?

Em
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2008-05-16 : 09:34:08
I think that's what he means...
another option is to just set the database to Simple recovery model

quote:
Originally posted by elancaster

quote:
Originally posted by jen

you don't want to do that because the reason for the constraint is so you don't get orphaned rows...

if you really want to do that... remove the constraint completely so you don't have to remove and recreate all the time you want to truncate

quote:
Originally posted by mangalau

I have a large table and i wanna delete it but with where constraints
is there a way , that i can do that without filling the log file , it's frustrating to truncate every time that log



--------------------
keeping it simple...



...actually Jen, i don't think that's what the OP meant? I think what they're saying is that they want to do...

delete from table1
where col = 'x'

...but don't want it to fill the transaction log? i.e. they would use 'truncate table' except that they need to a 'where' clause

mangalau - is that what you mean?

Em



--------------------
keeping it simple...
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-05-16 : 13:16:55
you can still use the SET ROWCOUNT command in 2005. So, that is one way to do it in batches. Or you can use the ROW_NUMBER() function to restric records. Here is one way using a loop to delete chunks of 10,000 at a time:
DECLARE @RowCount
SET @RowCount = 1 --Prime the loop


WHILE @RowCount > 0
BEGIN
SET ROWCOUNT 10000

DELETE MyTable
WHERE MyCol = 'foo'

SET @RowCount = @@ROWCOUNT
END
Go to Top of Page
   

- Advertisement -