B
brainpower
Unregistered / Unconfirmed
GUEST, unregistred user!
以下是DELPHI5.0/SQLserver7.0
我有一主從表 ord_hd/ord_detail,以 no相連
當刪除主表一條記錄后要刪除 detail中所有no相同的記錄,
可用如下代碼;
if not DBase.InTransaction Then DBase.StartTransaction;
Qy_ord_detail.First;
while not(Qy_ord_detail.Eof) do //先刪明細表
begin
Modi_stock; //先減庫存的過程,再刪明細記錄
Qy_ord_detail.Delete;
Qy_ord_detail.ApplyUpdates;
Qy_ord_detail.CommitUpdates;
end;
Qy_ord_hd.Delete; //再刪主表
Qy_ord_hd.ApplyUpdates;
Qy_ord_hd.CommitUpdates;
if DBase.InTransaction then DBase.Commit;
這段代碼可用如下觸發器:
CREATE TRIGGER TR_ord_hd ON dbo.ord_hd
FOR DELETE
AS
DELETE ord_detail
FROM ord_detail
WHERE no IN (SELECT no FROM DELETED)
但是DELETE-SQL語句是批次更新數據庫的呀,如何實現減庫存的動作(Modi_stock)?
因為每刪除一筆明細記錄,庫存數要變化!
對不起我現在只有50分,快斷炊了
我有一主從表 ord_hd/ord_detail,以 no相連
當刪除主表一條記錄后要刪除 detail中所有no相同的記錄,
可用如下代碼;
if not DBase.InTransaction Then DBase.StartTransaction;
Qy_ord_detail.First;
while not(Qy_ord_detail.Eof) do //先刪明細表
begin
Modi_stock; //先減庫存的過程,再刪明細記錄
Qy_ord_detail.Delete;
Qy_ord_detail.ApplyUpdates;
Qy_ord_detail.CommitUpdates;
end;
Qy_ord_hd.Delete; //再刪主表
Qy_ord_hd.ApplyUpdates;
Qy_ord_hd.CommitUpdates;
if DBase.InTransaction then DBase.Commit;
這段代碼可用如下觸發器:
CREATE TRIGGER TR_ord_hd ON dbo.ord_hd
FOR DELETE
AS
DELETE ord_detail
FROM ord_detail
WHERE no IN (SELECT no FROM DELETED)
但是DELETE-SQL語句是批次更新數據庫的呀,如何實現減庫存的動作(Modi_stock)?
因為每刪除一筆明細記錄,庫存數要變化!
對不起我現在只有50分,快斷炊了