PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You have a database that contains the tables shown in the exhibit. (Click the Exhibit button.)

You need to create a view named uv_CustomerFullName to meet the following
requirements:
• The code must NOT include object delimiters.
• The view must be created in the Sales schema.
• Columns must only be referenced by using one-part names.
• The view must return the first name and the last name of all customers.
• The view must prevent the underlying structure of the customer table from being
changed.
• The view must be able to resolve all referenced objects, regardless of the user’s
default schema.
Which code segment should you use?
To answer, type the correct code in the answer area.

PrepAway - Latest Free Exam Questions & Answers

Answer: See the explanation.

Explanation:
CREATE VIEW Sales.uv_CustomerFullName
WITH SCHEMABINDING
AS
SELECT FirstName, LastName
FROM Sales.Customers

Reference:
http://msdn.microsoft.com/en-us/library/ms187956.aspx

11 Comments on “Which code segment should you use?

  1. siddique says:

    The views must be created in the sales schema. However, the table given in the question is normal without any schema. Therefore, it should appear as Customers

    Create View Sales.uv_CustomerFullName
    With Schemabinding
    AS
    Select FirstName, LastName
    From Customers




    0



    0
  2. Thao says:

    The view must be able to resolve all referenced objects, regardless of the user’s
    default schema.

    >>> Doesn’t it mean that we have to put “From Sales.Customers” so that it doesn’t matter what the user’s default schema is, the server will know that it has to look in Sales schema for Customer table.




    0



    0
  3. Yommy O. says:

    The FROM clause of the view definition, has to reference a table that could be accessed by users belonging to ANY schema: the ‘dbo’ schema. Hence, the correct query is:

    CREATE VIEW Sales.uv_CustomerFullName
    WITH SCHEMABINDING
    AS
    SELECT FirstName, LastName
    FROM dbo.Customers;

    This way, user access need be granted only for the ‘uv_CustomerFullName’ view. If however, the view definition had included a “FROM Sales.Customers” clause, users referencing the view from a schema other than the ‘Sales’ schema would have required access to the underlying SALES table; and “to resolve all referenced objects”, wouldn’t be realistic.




    0



    0
  4. Wojtek says:

    Also:
    “When you use SCHEMABINDING, the select_statement must include the two-part names (schema.object) of tables, views, or user-defined functions that are referenced”

    https://msdn.microsoft.com/en-us/library/ms173846.aspx

    So if FirstName and LastName were in a schema they would have to be referenced with schema.object syntax which would violate the question’s condition:Columns must only be referenced by using one-part names.




    0



    0
  5. botmac says:

    @Wojtek: You don’t give schema names to columns, so the last part of your post is wrong. I think, the question should be showing the Sales schema in the tables. Without that schema name, dbo.Customers should be correct.




    0



    0

Leave a Reply