Question
The purpose of this assignment is to alter and apply the trigger code to the Person.Person table in the Adventure Works database. First, amend the
The purpose of this assignment is to alter and apply the trigger code to the Person.Person table in the Adventure Works database.
First, amend the trigger code (below) to fire correctly on the "Person.Person" table. Next, apply the trigger code provided below to the "Person.Person" table to track the number of modifications of data for the table. Check that the trigger worked by updating four records in the "Person.Person" table. Create a Word document which includes the altered trigger code, result table, and a screenshot of the fired trigger results.
- Add the "Title" 'Mr.' to 'Ken J Snchez'
- Add the "MiddleName" 'Timothy' to 'Michael Raheem'
- Add the "Title" 'Ms.' and change the "MiddleName" to 'Heather' for 'Samantha H Smith'
- Add the "Title" 'Mrs.' and change the "LastName" to 'Thompson' for 'Lori K Penor'
Trigger Code
CREATE TRIGGER [].[trgUpdatedColumns]
ON [].[] FOR UPDATE
AS
SET NOCOUNT ON
DECLARE @i AS int, @num_cols AS int
DECLARE @UpdCols TABLE(ordinal_position int NOT NULL PRIMARY KEY)
SET @num_cols =
(SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = ''
AND TABLE_NAME = '')
SET @i = 1
WHILE @i <= @num_cols
BEGIN
IF (SUBSTRING(COLUMNS_UPDATED(),(@i - 1) / 8 + 1, 1))
& POWER(2, (@i - 1) % 8) = POWER(2, (@i - 1) % 8)
INSERT INTO @UpdCols VALUES(@i)
SET @i = @i + 1
END
SELECT COLUMN_NAME AS Updated_Column, GETDATE() AS DateModified
FROM INFORMATION_SCHEMA.COLUMNS AS C JOIN @UpdCols AS U
ON C.ORDINAL_POSITION = U.ordinal_position
WHERE TABLE_SCHEMA = ''
AND TABLE_NAME = ''
ORDER BY C.ORDINAL_POSITION
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started