exam questions

Exam 70-762 All Questions

View all questions & answers for the 70-762 exam

Exam 70-762 topic 1 question 152 discussion

Actual exam question from Microsoft's 70-762
Question #: 152
Topic #: 1
[All 70-762 Questions]

You have a database with multiple tables. You must insert data into the tables by using views.
Which of the following two statements best describes an updatable view?
NOTE: Each correct selection is worth one point.

  • A. The view must not include the primary key of the table.
  • B. The view may include GROUP BY or HAVING statements.
  • C. The view may include a composite field.
  • D. Each view must reference columns from one table.
  • E. The view must not include subqueries.
Show Suggested Answer Hide Answer
Suggested Answer: BD 🗳️
B: The columns being modified must not be affected by GROUP BY, HAVING, or DISTINCT clauses.
D: Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.
Incorrect Answers:
A: Primary keys are allowed.
C: The columns cannot be derived in any other way, such as through the following:
A computation. The column cannot be computed from an expression that uses other columns.
E: The restrictions apply to any subqueries in the FROM clause of the view, just as they apply to the view itself.
References:
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql?view=sql-server-2017

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
sathyag
Highly Voted 5 years, 5 months ago
Answer is DE
upvoted 55 times
Vijayglobal
5 years, 1 month ago
https://www.w3resource.com/sql/update-views/sql-update-views.php for quick reference.
upvoted 3 times
...
MML
4 years, 11 months ago
I agree
upvoted 1 times
...
...
othman_ee
Highly Voted 5 years, 5 months ago
answer: CD
upvoted 7 times
Chocho
4 years, 11 months ago
u can't update a composite columns...
upvoted 1 times
Lukis92
4 years, 11 months ago
The description doesn't point that composite column will be updated. Definitely that view can have composite columns and be updateable.
upvoted 1 times
Lukis92
4 years, 10 months ago
My fault. The task says about insertion not update.
upvoted 1 times
...
...
...
...
HA2020
Most Recent 4 years, 5 months ago
BC A. The view must not include the primary key of the table.: False B. The view may include GROUP BY or HAVING statements.: only columns being modified can't be affected by GROUP BY or HAVING clauses. C. The view may include a composite field.: only affected columns can't be composite D. Each view must reference columns from one table.: it can as long as the update/insert affects one table only. E. The view must not include subqueries.: no such restriction
upvoted 1 times
...
BrianILyas
4 years, 6 months ago
Given answer is correct and is fully explained in the explanation of the answer. Correct Answer: BD B: The columns being modified must not be affected by GROUP BY, HAVING, or DISTINCT clauses. D: Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table. Incorrect Answers: A: Primary keys are allowed. C: The columns cannot be derived in any other way, such as through the following: A computation. The column cannot be computed from an expression that uses other columns. E: The restrictions apply to any subqueries in the FROM clause of the view, just as they apply to the view itself. References: https://docs.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql?view=sql-server-2017
upvoted 1 times
...
Alex5x
4 years, 7 months ago
The question is indeed tricky and you really cannot answer this until you read the documentation carefully and then confirm it by writing some code. So, let's start from the documenation (https://docs.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql?view=sql-server-ver15#updatable-views) and then exclude the wrong options: A. The view must not include the primary key of the table. This is definitely wrong. Primary keys are not only allowed, but also desirable. If your PK is not generated automatically then how are you going to insert a new record without providing a new PK?
upvoted 1 times
Alex5x
4 years, 7 months ago
D. Each view must reference columns from one table. The documentation says: "Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table." Do you see the difference? If not, then let me explain. The view can join as many tables as you want and select columns from all those tables. However, when it comes to INSERT into the view, you can only specify the columns from one table. So, option D is wrong.
upvoted 1 times
...
Alex5x
4 years, 7 months ago
E. The view must not include subqueries. This is wrong. Subqueries are allowed. The documentation does not include this restriction.
upvoted 1 times
...
Alex5x
4 years, 7 months ago
The remaining options are correct: B. The view may include GROUP BY or HAVING statements. C. The view may include a composite field. The documentation says: "The columns being modified are not affected by GROUP BY, HAVING, or DISTINCT clauses.", "The columns being modified cannot be computed from an expression that uses other columns." The key words here are "The columns being modified". So, if you have such columns in the view, but you are not modifying them, then this is not a problem.
upvoted 1 times
...
Alex5x
4 years, 7 months ago
Now it's time to prove everything said above by writing a simple test. Let's create two tables and one view: CREATE TABLE dbo.TestTable ( ID int NOT NULL PRIMARY KEY, Comment varchar(100) NOT NULL ) GO CREATE TABLE dbo.TestTable2 ( ID int NOT NULL PRIMARY KEY, Comment varchar(100) NOT NULL ) GO
upvoted 1 times
...
...
databasejamdown
4 years, 8 months ago
B and C is correct. I wrote code to test all the answers. A is incorrect because you can include the primary key. B is correct because you can include gropu by fields as long as you don't attempt to update it. C is correct because you can include a composite field as long as you don't attempt to update it. D is incorrect because the view can include fields from multiple tables as long as the fields you are updating are from a single table. E is incorrect because you can include subqueries as long as you're updating fields from a single table only. All of these points were tested in sample views.
upvoted 3 times
...
Cococo
4 years, 9 months ago
okay, all MAY answers are correct. PK - wrong, D - this rule is for DML, not for the view :) E - subqueries should follow the the same rules, all of them here - https://docs.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql?view=sql-server-2017 updateable views section
upvoted 1 times
Cococo
4 years, 9 months ago
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql?view=sql-server-ver15 Updatable Views: You can modify the data of an underlying base table through a view, as long as the following conditions are true: - UPDATE, INSERT, and DELETE statements, must reference columns from only one base table. - The columns being modified in the view must directly reference the underlying data in the table columns. - The columns being modified are not affected by GROUP BY, HAVING, or DISTINCT clauses
upvoted 1 times
Cococo
4 years, 9 months ago
The previous restrictions apply to any subqueries in the FROM clause of the view, just as they apply to the view itself. Generally, the Database Engine must be able to unambiguously trace modifications from the view definition to one base table. So, an updatable view can have more than one base table, can have aggregates, can have subqueries and agg functions. The rules are for INSERT, not for the VIEW, Now, read the question: "Which of the following two statements best describes an updatable view?"
upvoted 1 times
...
...
...
melvin9900
4 years, 10 months ago
Answer D and E The view is defined based on one and only one table. 2. The view must include the PRIMARY KEY of the table based upon which the view has been created. 3. The view should not have any field made out of aggregate functions. 4. The view must not have any DISTINCT clause in its definition. 5. The view must not have any GROUP BY or HAVING clause in its definition. 6. The view must not have any SUBQUERIES in its definitions. 7. If the view you want to update is based upon another view, the later should be updatable. 8. Any of the selected output fields (of the view) must not use constants, strings or value expressions
upvoted 3 times
...
LeonLeon
4 years, 11 months ago
D is wrong because you do not have to reference just columns from one table in the view aslong as you do not update fields of more tables: ALTER view [dbo].[vwTest] as Select T.ID, discription, comment, discription + comment test, S.object_id from Test T left join sys.objects S On T.id = S.create_date GO Update vwTest set comment = 'bla bla blaa' Where id =2
upvoted 1 times
...
LeonLeon
4 years, 11 months ago
C is coorrect because this works aslong as the update is not over the computed column ALTER view [dbo].[vwTest] as Select ID, discription, comment, discription + comment test from Test GO Update vwTest set comment = 'bla bla blaa' Where id =2
upvoted 2 times
...
stm22
4 years, 11 months ago
The columns being modified in the view must directly reference the underlying data in the table columns. The columns cannot be derived in any other way, such as through the following: An aggregate function: AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV, STDEVP, VAR, and VARP. A computation. The column cannot be computed from an expression that uses other columns. Columns that are formed by using the set operators UNION, UNION ALL, CROSSJOIN, EXCEPT, and INTERSECT amount to a computation and are also not updatable. The columns being modified are not affected by GROUP BY, HAVING, or DISTINCT clauses. TOP is not used anywhere in the select_statement of the view together with the WITH CHECK OPTION clause. The previous restrictions apply to any subqueries in the FROM clause of the view, just as they apply to the view itself. Generally, the Database Engine must be able to unambiguously trace modifications from the view definition to one base table. For more information, see Modify Data Through a View. https://docs.microsoft.com/en-us/sql/relational-databases/views/modify-data-through-a-view?view=sql-server-ver15
upvoted 1 times
...
stm22
4 years, 11 months ago
B and D The B and D choices are vague, but the explanation contains the real B and D: B: The columns being modified must not be affected by GROUP BY, HAVING, or DISTINCT clauses. D: Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table. Updatable Views You can modify the data of an underlying base table through a view, as long as the following conditions are true: Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.
upvoted 2 times
...
amar111
5 years, 1 month ago
Answer BD in correct . Read the updatable view section from below link. https://docs.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql?view=sql-server-ver15
upvoted 4 times
Chocho
4 years, 11 months ago
you right ! The answers is correct. read the updatable view section !
upvoted 1 times
MML
4 years, 11 months ago
Read more carefully.. You can modify the data of an underlying base table through a view, as long as the following conditions are true: The columns being modified are not affected by GROUP BY, HAVING, or DISTINCT clauses. The columns being modified in the view must directly reference the underlying data in the table columns,the columns cannot be derived from any computation or any aggregation ..
upvoted 4 times
...
...
...
iYoung
5 years, 2 months ago
For a view to be updatable, there must be a one-to-one relationship between the rows in the view and the rows in the underlying table. There are also certain other constructs that make a view nonupdatable. To be more specific, a view is not updatable if it contains any of the following: Aggregate functions or window functions (SUM(), MIN(), MAX(), COUNT(), and so forth) DISTINCT GROUP BY HAVING UNION or UNION ALL Subquery in the select list https://dev.mysql.com/doc/refman/8.0/en/view-updatability.html
upvoted 2 times
Anette
4 years, 11 months ago
From this answer it is DE, as sthyag mentions ant has most likes
upvoted 5 times
...
...
NickMane
5 years, 2 months ago
CE is correct
upvoted 6 times
...
New_user
5 years, 5 months ago
The B answer conflicts with given answers' explanation
upvoted 5 times
lh2607
4 years, 7 months ago
The answer B is actually incorrect in the options, however it's correct in the explanation. I believe the answer for Option B should be along the lines of: The columns being modified must not be affected by GROUP BY, HAVING, or DISTINCT clauses.
upvoted 1 times
...
...
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.

SaveCancel
Loading ...