SELECT * INTO CustomersGer FROM Customers WHERE Customers.Country = 'Germany' SELECT * INTO CustomersMex FROM Customers WHERE Customers.Country = 'Mexico' GO |
CREATE VIEW CustomersView AS SELECT * FROM CustomersGer UNION SELECT * FROM CustomersMex GO |
CREATE TRIGGER Customers_Update2 ON CustomersView INSTEAD OF UPDATE AS DECLARE @Country nvarchar(15) SET @Country = (SELECT Country FROM Inserted) IF @Country = 'Germany' BEGIN UPDATE CustomersGer SET CustomersGer.Phone = Inserted.Phone FROM CustomersGer JOIN Inserted ON CustomersGer.CustomerID = Inserted.CustomerID END ELSE IF @Country = 'Mexico' BEGIN UPDATE CustomersMex SET CustomersMex.Phone = Inserted.Phone FROM CustomersMex JOIN Inserted ON CustomersMex.CustomerID = Inserted.CustomerID END |
UPDATE CustomersView SET Phone = ' 030-007xxxx' WHERE CustomerID = 'ALFKI' SELECT CustomerID, Phone FROM CustomersView WHERE CustomerID = 'ALFKI' SELECT CustomerID, Phone FROM CustomersGer WHERE CustomerID = 'ALFKI' |
CREATE TRIGGER [calT1T2T3] ON dbo.DCLB FOR INSERT,UPDATE AS update P SET /**//* 计算方差的触发器 */ P.T1=(I.P1+I.P2+I.P3+I.P4+I.P5+I.P6), P.T2=(I.Y1+I.Y2+I.Y3+I.Y4+I.Y5+I.Y6 ), P.T3=SQRT(P.T1*P.T1+P.T2*P.T2) FROM DCLB AS P INNER JOIN Inserted AS I ON P.SID = I.SID |