트리거 vs. 계산 열
데이터베이스를 계속 분석하던 중 흥미로운 객체 두 개를 찾았습니다.
SalesWithPrice테이블에는TotalAmount를Quantity * Price로 계산하는 열이 있습니다. 이는 같은 테이블의 열을 사용해 계산하는 계산 열(computed column) 로 구현되어 있습니다.트리거
SalesCalculateTotalAmount는SalesWithoutPrice테이블에 생성되어 있습니다.SalesWithoutPrice테이블에는Price열이 없기 때문에TotalAmount에 계산 열을 사용할 수 없습니다. 이 트리거는Products테이블의Price열을 사용해 이러한 제약을 극복합니다.
이 연습은 강의의 일부입니다
SQL Server에서 트리거 구축 및 최적화
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
-- Add the following rows to the table
INSERT INTO ___ (Customer, Product, Price, Currency, Quantity)
VALUES ('Fruit Mag', 'Pomelo', 1.12, 'USD', 200),
('VitaFruit', 'Avocado', 2.67, 'USD', 400),
('Tasty Fruits', 'Blackcurrant', 2.32, 'USD', 1100),
('Health Mag', 'Kiwi', 1.42, 'USD', 100),
('eShop', 'Plum', 1.1, 'USD', 500);
-- Verify the results after adding the new rows
SELECT * FROM SalesWithPrice;