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

CREATE TRIGGER muutus3 ON Tooted_vaade INSTEAD OF UPDATE
  AS
BEGIN
  PRINT 'Kuku'
END

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
