Home > SQL Server > Triger Sql Server – Delete Related data on others Table

Triger Sql Server – Delete Related data on others Table

Triger bisa digunakan untuk menghapus data pada tabel yang lain tanpa lewat program aplikasi.

contaoh Triger :

CREATE TRIGGER MyTriger ON MRM_DATA
FOR DELETE
AS
DECLARE @intRowCount int
SELECT @intRowCount = @@RowCount
IF @intRowCount > 0
BEGIN
DELETE MRM_IR_RATES
WHERE DATA_ID IN (SELECT DATA_ID FROM deleted)
DELETE MRM_GOV_ZERO_RATES
WHERE DATA_ID IN (SELECT DATA_ID FROM deleted)
DELETE MRM_FXO_VOLS
WHERE DATA_ID IN (SELECT DATA_ID FROM deleted)
DELETE MRM_FX_RATES
WHERE DATA_ID IN (SELECT DATA_ID FROM deleted)
DELETE MRM_FIS_PRICES
WHERE DATA_ID IN (SELECT DATA_ID FROM deleted)
DELETE MRM_CORP_ZERO_RATES
WHERE DATA_ID IN (SELECT DATA_ID FROM deleted)
END
GO

Categories: SQL Server Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: