use pood CREATE VIEW Tooted_vaade as SELECT * FROM Tooted_tbl SELECT * FROM tooted_vaade DROP TRIGGER muutus1 CREATE TRIGGER muutus1 ON Tooted_tbl FOR UPDATE AS BEGIN UPDATE Tooted_tbl SET Versioon=Versioon+1 WHERE TooteID=(SELECT TooteID FROM inserted) END DROP TRIGGER muutus2 CREATE TRIGGER muutus2 ON Tooted_tbl FOR UPDATE AS IF @@nestlevel = 1 update Tooted_tbl SET Versioon = t.Versioon + 1 from Tooted_tbl as t inner join inserted as i on t.TooteID = i.TooteID SELECT * FROM tooted_tbl UPDATE Tooted_tbl SET Kirjeldus='Pehme5' WHERE TooteID=1 OR TooteID=2 ALTER TRIGGER muutus3 ON Tooted_vaade INSTEAD OF UPDATE AS BEGIN update Tooted_tbl SET Versioon = t.Versioon + 1 , Nimetus = i.Nimetus , Hind = i.Hind , Kirjeldus = i.Kirjeldus , Laoseis = i.Laoseis , PiltSuur = i.PiltSuur , PiltMini = i.PiltMini , Nahtav = i.Nahtav from Tooted_tbl as t inner join inserted as i on t.TooteID = i.TooteID END CREATE TABLE #tabel1 (kood int, jutt varchar(20)) CREATE TABLE #tabel2 (kood int, jutt varchar(20)) INSERT #tabel1 VALUES (1, 'jutt1') INSERT #tabel1 VALUES (2, 'jutt2') INSERT #tabel1 VALUES (3, 'jutt3') INSERT #tabel2 VALUES (2, 'jutt4') INSERT #tabel2 VALUES (3, 'jutt5') INSERT #tabel2 VALUES (4, 'jutt6') SELECT * FROM #tabel1 SELECT * FROM #tabel2 SELECT * FROM #tabel1 as t1 INNER JOIN #tabel2 as t2 ON t1.kood = t2.kood UPDATE #tabel1 SET jutt = t1.jutt + t2.jutt FROM #tabel1 as t1 INNER JOIN #tabel2 as t2 ON t1.kood = t2.kood SELECT * FROM tooted_vaade UPDATE Tooted_vaade SET Kirjeldus='Pehme6' WHERE TooteID=1 INSERT INTO Tooted_tbl(Nimetus, Hind) VALUES ('Riia peenleib', 4); CREATE TRIGGER linnamuutus ON linnad FOR INSERT AS INSERT INTO logi (aeg, toiming, andmed) SELECT GETDATE(), 'lisati', linnanimi FROM inserted