#8, please help write query using SQL Management Studio and run to show output,
ID: 3919803 • Letter: #
Question
#8, please help write query using SQL Management Studio and run to show output, thanks
hage e ushd tee for the juu use condo with the condo ID 3 in location 1 to $525 this stored /8. Assume the OWNER table contains a column named TOTAL-FEES that represents total monthly condo fee for all condos owned by that owner. Write the code in PLSO. When inserting a row in the CONDO UNIT table, add the condo fee to the total b. When updating a row in the CONDO_UNIT table, add the difference beltweenthe T-SQL for the following triggers following the style shown in the text. condo fees for the appropriate owner. new condo fee and the old condo fee to the total condo fees for the approprate owner. c. When deleting a row in the CONDO_UNIT table, subtract the condo feefrom the a condo fees for the appropriate owner. On ond CEExplanation / Answer
Answer to Question a)
CREATE TRIGGER AfterINSERTTrigger on [CONDO_UNIT]
FOR INSERT
AS DECLARE @UnitId INT,
@OwnerName VARCHAR(50),
@CondoFee DECIMAL (10, 2),
SELECT @UnitId = ins.UNITID FROM INSERTED ins;
SELECT @OwnerName = ins.OWNERNAME FROM INSERTED ins;
SELECT @CondoFee = ins.CONDOFEE FROM INSERTED ins;
UPDATE [OWNER]
SET [TotalFee] = i.Result,
FROM [SELECT(O1.TotalFee + U1.CONDOFEE) AS Result FROM OWNER O1, CONDO_UNIT U1] i
WHERE i.OWNERNAME = CONDO_UNIT.OWNERNAME;
PRINT 'We Successfully Fired the Second AFTER UPDATE Triggers in SQL Server.'
GO
Answer to Question B)
CREATE TRIGGER AfterUPDATETrigger on [CONDO_UNIT]
FOR UPDATE
AS DECLARE @UnitId INT,
@OwnerName VARCHAR(50),
@CondoFee DECIMAL (10, 2),
SELECT @UnitId = ins.UNITID FROM INSERTED ins;
SELECT @OwnerName = ins.OWNERNAME FROM INSERTED ins;
SELECT @CondoFee = ins.CONDOFEE FROM INSERTED ins;
IF UPDATE()
BEGIN
SET @ActionPeformed = 'Updated Yearly Income'
END
UPDATE [OWNER]
SET [TotalFee] = [SELECT @total = ins.TOTALFEE FROM INSERTED ins] - [SELECT a.*, d.* FROM INSERTED a JOIN DELETED d ON (a.CONDOFEE=d.CONDOFEE)] ,
WHERE OWNER.OWNERNAME = CONDO_UNIT.OWNERNAME;
PRINT 'We Successfully Fired the Second AFTER UPDATE Triggers in SQL Server.'
GO
Answer to Question C)
CREATE TRIGGER AfterDELETETrigger on [CONDO_UNIT]
FOR DELETE
AS DECLARE @UnitId INT,
@OwnerName VARCHAR(50),
@CondoFee DECIMAL (10, 2),
SELECT @UnitId = ins.UNITID FROM DELETED ins;
SELECT @OwnerName = ins.OWNERNAME FROM DELETED ins;
SELECT @CondoFee = ins.CONDOFEE FROM DELETED ins;
UPDATE [OWNER]
SET [TotalFee] = i.Result,
FROM [SELECT(O1.TotalFee - U1.CONDOFEE) AS Result FROM OWNER O1, CONDO_UNIT U1] i
WHERE i.OWNERNAME = CONDO_UNIT.OWNERNAME;
PRINT 'We Successfully Fired the Second AFTER UPDATE Triggers in SQL Server.'
GO
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.