Showing posts with label dbo. Show all posts
Showing posts with label dbo. Show all posts

Friday, February 24, 2012

Delete statement again

set rowcount 100000
declare @.a int
while 1=1
begin
begin tran del1
delete from dbo.extt_vpm_ldr_stg_2
select @.a = @.@.rowcount
print @.a
commit tran del1
if @.a < 100000 break;
end
Hi
TOTAL TABLE SIZE - 650 000 records
I am using the above statement to delete in chunks on 100000.
After every 100000 I have put a COMMIT TRAN. Hence as per the logic it
should delete 100000 commit and delete the next 100000.
And the transaction log is suppose 100MB before the statement is
executed. It is increasing in steps of some 30MB for each delete to
upto some 250MB and then goes back to some 50MB.
What we need is the transaction log must increase for every delete and
drop and again increase and so on.
How can the above statement be modified to take care of this behaviour?
Please reply asap.
Thanks
HarishIs your databsae set to simple recovery mode? If it is set to full recovery
the transaction log will grow until you backup or truncate the log.
Note if you set to simple recovery mode you will not be able to use log
backups for log shipping or disaster recovery. Same thing if you truncate
the log (Backup Log <database name> with truncate_only).
"harish" <harish.prabhala@.gmail.com> wrote in message
news:1131552570.094908.5060@.z14g2000cwz.googlegroups.com...
> set rowcount 100000
> declare @.a int
> while 1=1
> begin
> begin tran del1
> delete from dbo.extt_vpm_ldr_stg_2
> select @.a = @.@.rowcount
> print @.a
> commit tran del1
> if @.a < 100000 break;
> end
>
> Hi
> TOTAL TABLE SIZE - 650 000 records
> I am using the above statement to delete in chunks on 100000.
> After every 100000 I have put a COMMIT TRAN. Hence as per the logic it
> should delete 100000 commit and delete the next 100000.
> And the transaction log is suppose 100MB before the statement is
> executed. It is increasing in steps of some 30MB for each delete to
> upto some 250MB and then goes back to some 50MB.
> What we need is the transaction log must increase for every delete and
> drop and again increase and so on.
> How can the above statement be modified to take care of this behaviour?
> Please reply asap.
> Thanks
> Harish
>

Friday, February 17, 2012

DELETE Procedure. How to do this?

Hello,

I created a delete procedure which is working but I still have a
problem.

When I delete a localized content from dbo.by27_ContentLocalized given
a ContentName and ContentCulture I want to check if this is the only
record in ContentLocalized for that ContentName.

If it is then I also want to delete the record in dbo.by27_Content
which has that ContentName.

How can I do this?

Thanks,
Miguel

Here is my DELETE procedure:

-- Define the procedure parameters
@.ContentCulture NVARCHAR(5),
@.ContentName NVARCHAR(100)

AS

-- Allows @.@.ROWCOUNT and the return of number of records when
ExecuteNonQuery is used
SET NOCOUNT OFF;

-- Declare and define ContentId
DECLARE @.ContentId UNIQUEIDENTIFIER;
SELECT @.ContentId = ContentId FROM dbo.by27_Content WHERE ContentName =
@.ContentName

-- Check if ContentId is Not Null
IF @.ContentId IS NOT NULL
BEGIN

-- Check if ContentId is Null
IF @.ContentCulture IS NULL
BEGIN

-- Delete all localized contents from dbo.by27_ContentLocalized
DELETE
FROM dbo.by27_ContentLocalized
WHERE ContentId = @.ContentId

-- Delete content from dbo.by27_Content
DELETE
FROM dbo.by27_Content
WHERE ContentName = @.ContentName;

END
ELSE

-- Delete localized content from dbo.by27_ContentLocalized
DELETE
FROM dbo.by27_ContentLocalized
WHERE (ContentID = @.ContentID AND ContentCulture = @.ContentCulture)

END

shapper:

When I delete a localized content from dbo.by27_ContentLocalized given
a ContentName and ContentCulture I want to check if this is the only
record in ContentLocalized for that ContentName.

Can you explain what you mean by "only record in ContentLocalized for that ContentName". Do you mean check if there is only 1 record and delete it? or something else?

|||

I mean that when a record in by27_ContentLocalized is deleted it checks if it is the only one which is related with its parent in by27_Content.

If it is then it deletes also its parent in by27_Content, see?

Thanks,

Miguel

|||

How about adding something like this to the end of the procedure...

IF NOT EXISTS(SELECT * FROM by27_ContentLocalized WHERE ContentId = @.ContentID)
BEGIN
DELETE FROM by27_Content WHERE ContentID = @.ContentID
END

I hope this helps,

Steve

|||You can create a DELETE trigger on dbo.by27_ContentLocalized table, which will check to see whether the deleted row is the only record in ContentLocalized for that ContentName. For example:

CREATE?TRIGGER trg_CheckDeleteCL ON dbo.by27_ContentLocalized AFTER DELETE
AS
SELECT 1 FROM dbo.by27_ContentLocalized b,deleted d
WHERE b.ContentName=d.ContentName
IF(@.@.ROWCOUNT=0)
BEGIN
DECLARE @.msg NVARCHAR(2000)
DELETE dbo.by27_Content FROM dbo.by27_Content c, deleted d
WHERE c.ContentName=d.ContentName
SELECT @.msg='The record with ContentName='''+ContentName+'''deleted from dbo.by27_Content'
FROM deleted
PRINT @.msg
END
go