Blog Of Sem: Sql toplu hareket görenleri kasmadan silme

Sql toplu hareket görenleri kasmadan silme


declare @counter int
declare @numOfRecords int
declare @batchsize int

set @numOfRecords = 700924 --burdaki rakam databasei acip tables yazisini secip f7 basinca rowcountu en cok olan rakam

set @counter = 0
set @batchsize = 2500

set rowcount @batchsize
while @counter < (@numOfRecords/@batchsize) +1
begin
set @counter = @counter + 1
delete Erp_InventoryReceiptItem

update Erp_Invoice set InventoryReceiptId = null

update Erp_InventoryReceiptAttachment set  InventoryReceiptId = null

delete Erp_InventoryReceiptAttachment

delete Erp_InvoiceAttachment

delete Erp_WorkOrderProduction
UPDATE  Erp_InventoryReceiptItem set InventoryReceiptId=null
delete Erp_InventoryReceipt

update Erp_InventoryReceipt set InvoiceId=null
delete Erp_Invoice

delete Erp_BankAccountTotal

delete Erp_BankCredit
update Erp_CurrentAccountReceipt set BankReceiptId=null
delete Erp_BankReceiptItem

update Erp_ChequeReceipt set BankReceiptId=null

delete Erp_ChequeReceiptItem

delete Erp_ChequeReceiptAttachment

delete Erp_ChequeReceipt

delete Erp_BankReceiptAttachment

delete Erp_BankReceipt

delete Erp_CashTotalItem

delete Erp_CashTotal

delete Erp_Cheque

delete Erp_OrderReceiptItem

delete Erp_OrderReceiptAttachment

delete Erp_OrderReceipt

delete Erp_ContractItem

delete Erp_ContractAttachment

delete Erp_Contract

update Erp_InventoryReceipt set CurrentAccountReceiptId = null
delete Erp_CurrentAccountReceiptItem

delete Erp_CurrentAccountReceiptAttachment

delete Erp_CurrentAccountReceipt

delete Erp_CurrentAccountTotal

delete Erp_QuotationReceiptItem

delete Erp_QuotationReceiptAttachment

delete Erp_QuotationReceipt

delete Erp_DemandReceiptItem

delete Erp_DemandReceiptAttachment

delete Erp_DemandReceipt

delete Erp_WorkOrderItem

delete Erp_WorkOrderAttachment

delete Erp_WorkOrderExplanation

delete Erp_WorkOrder

delete Erp_GLReceiptItem
update Erp_InventoryReceipt set GLReceiptId=null

delete Erp_GLReceipt

Delete Erp_InventoryTotal

delete Erp_ReceiptPaymentItem

delete Meta_ForexRate

delete Erp_ServiceTotal

Delete Erp_GLAccountTotal

delete Erp_BankAccountTotal
update Erp_InventoryReceipt set PosReceiptId=null
delete erp_pos
delete Erp_InventoryReceipt
delete RPL_TaskTarget
delete Rpl_TaskItem
delete RPL_Task
delete Rpl_Xref
delete [LiveHareketler].[dbo].[Replication]
end
set rowcount 0


truncate table Log_Transaction


shrink işlemi:
USE LiveHareketler;
GO
ALTER DATABASE LiveHareketler
SET RECOVERY SIMPLE;
GO

--Datadakı log dosyasını shrınk yap yani database sağ tıkla task shrink files log->reorganize page 0 ve tamam ve sonrasındada yine databasee sağ tık task shrink database ok

ALTER DATABASE LiveHareketler
SET RECOVERY FULL;
GO