2010-10-22 23 views
-3

我想寫一個存儲過程,它會從90天以前的dirstaging.trr.table1和dirstaging.trr.table2中刪除記錄。相同的存儲過程將從dir.trr.ErrorTable中刪除dir.trr.table3和dir.trr.table4中沒有記錄的所有記錄。這個proc將接受變量@cleanup。我怎麼能寫storec proc哪些從table1和table2中刪除90天以前的舊記錄

注:我想是這樣,從表1和表2中選擇的所有記錄,並把他們在臨時表中,表1截斷和2對臨時表適用條件,以獲得最新的記錄,並在表1移動它們和2

我可以做不同的方式嗎?

感謝

+1

對於什麼數據庫,表,以及什麼是「舊記錄」的資格? – 2010-10-22 02:00:26

+1

請定義「舊記錄」 – akonsu 2010-10-22 02:00:29

+0

您應該在詢問如此一般的問題之前嘗試閱讀文檔。 http://dev.mysql.com/doc/refman/5.1/en/stored-routines-syntax.html – Andrew 2010-10-22 02:00:45

回答

2

既然你不給一個DDL我也沒辦法知道怎麼表的連接,什麼類型,這是我會怎麼做一個樣本。

create procedure myProc(@cleanup some_type) as 
    begin 
     delete dirstaging.trr.table1 
     where the_column < getdate() - 90 

     delete dirstaging.trr.table2 
     where the_column < getdate() - 90 

     -- join error table and table 3 and table 4 and where the rows exist in 3 & 4 delete from e 

     delete e 
     from dir.trr.ErrorTable e 
     left outer join dir.trr.table3 t3 on e.common_column = t3.common_column 
     left outer join dir.trr.table4 t4 on e.common_column = t4.common_column 
     where t3.common_column is null 
     or t4.common_column is null 

    end 
+0

對不起,我錯誤地提交。我編輯了我的問題。 – john 2010-10-22 02:04:49

相關問題