You have an application that uses a view to access data from multiple tables. You need to ensure that you can insert rows into the underlying tables by using the view. What should you do?
A.
Create an INSTEAD OF trigger on the view.
B.
Define the view by using the SCHEMABINDING option.
A is correct, as there are some restrictions to prevent from updating directly through view, but Instead of trigger doesn't have those kinds of restriction.
Views can be created in SQL Server WITH CHECK OPTION.
WITH CHECK OPTION will make sure that all INSERT and UPDATE statements executed against the view meet the restrictions in the WHERE clause, and that the modified data in the view remains visible after INSERT and UPDATE statements.
To test this, we will first create a table and insert some data in it:
CREATE TABLE table_1
(
id int,
data nvarchar(20)
)
INSERT INTO table_1
VALUES (1, 'a'), (2, 'b'), (3, 'c')
Next we will create a view using the WITH CHECK option:
CREATE VIEW view_1
AS
SELECT * FROM table_1
WHERE data like 'b%'
WITH CHECK OPTION
We can see only values in the data column that start with b:
SELECT * FROM view_1
view_with_check_select_1
If we try to insert into view value that doesn't meet the WHERE criteria (WHERE data like 'b%'), it will fail:
INSERT INTO view_1
VALUES (4, 'd')
INSTEAD OF triggers can be created on a view to make a view updatable. The INSTEAD OF trigger is executed instead of the data modification statement on which the trigger is defined. This trigger lets the user specify the set of actions that must happen to process the data modification statement. Therefore, if an INSTEAD OF trigger exists for a view on a specific data modification statement (INSERT, UPDATE, or DELETE), the corresponding view is updatable through that statement. For more information about INSTEAD OF triggers, see DML Triggers.
upvoted 4 times
...
This section is not available anymore. Please use the main Exam Page.70-464 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
mch185
4 years, 5 months agoWilliamzhou
4 years, 6 months agoKepty
4 years, 7 months agoLuzix
4 years, 7 months agohumba
5 years, 1 month agoBigBen
5 years, 7 months ago