SQL Server'da Tetikleyiciler Oluşturma ve Optimize Etme
Florin Angelescu
Instructor
INSERT, UPDATE, DELETE ile kullanılırBu örnekte kullanılan Products tablosu çıktısı:
| Product | Price | Currency | Quantity | Measure |
|---------|-------|----------|----------|---------|
| Apple | 2.00 | USD | 25000 | kg |
| Apricot | 1.55 | USD | 2500 | kg |
| Avocado | 3.00 | USD | 1000 | kg |
| Banana | 1.80 | USD | 35000 | kg |
ProductsDELETETrackRetiredProductsProducts tablosundan satırlar silindiğinde...
Bu satırlardaki gerekli bilgiyi RetiredProducts tablosuna kaydedin.
| Product | Price | Currency | Quantity | Measure |
|---------|-------|----------|----------|---------|
| Apple | 2.00 | USD | 25000 | kg |
| Apricot | 1.55 | USD | 2500 | kg | X
| Avocado | 3.00 | USD | 1000 | kg |
| Banana | 1.80 | USD | 35000 | kg |
| Product | Measure | RemovalDate |
|---------|---------|-------------|
| Apricot | kg | 19.04.2019 |
CREATE TRIGGER TrackRetiredProductsON ProductsAFTER DELETEAS INSERT INTO RetiredProducts (Product, Measure) SELECT Product, Measure FROM deleted;
| Özel tablo | INSERT | UPDATE | DELETE |
|---|---|---|---|
| inserted | yeni satırlar | yeni satırlar | YOK |
| deleted | YOK | güncellenen satırlar | silinen satırlar |
CREATE TRIGGER TrackRetiredProducts
ON Products
AFTER DELETE
AS
INSERT INTO RetiredProducts (Product, Measure)
SELECT Product, Measure
FROM deleted;
SQL Server'da Tetikleyiciler Oluşturma ve Optimize Etme