PrepAway - Latest Free Exam Questions & Answers

Which Transact-SQL statement should you run?

Note: This question is part of a series of questions that use the same or similar answer choices. An
answer choice may be correct for more than one question in the series. Each question is independent
of the other questions in this series. Information and details provided in a question apply only to that
question.
You create a table by running the following Transact-SQL statement:

You are developing a report that aggregates customer data only for the year 2014. The report requires that the
data be denormalized.
You need to return the data for the report.
Which Transact-SQL statement should you run?

PrepAway - Latest Free Exam Questions & Answers

A.

B.

C.

D.

E.

F.

G.

H.

9 Comments on “Which Transact-SQL statement should you run?

    1. overkill says:

      Why do you think D is denormalized? which normal form is it breaking?

      I initially thinked on 1NF by having the same attribute(year) spread in multiple columns. but there is only on spreading column in this query (2014) so there is no spreading of the same attribute for multiple columns.

      if we had 2014 and 2015. I would say right away that would be D). but as it is I’m doubtfully and would like to know what you thinked.

      I see denormalization in no query, unfortunately




      3



      0
      1. overkill says:

        I’ve updated recreated the exercise and eligible answers down below.
        the tabel is called BM_Customers instead of Customers, and I go for 2018 instead of 2014.

        As I said before, I see no denormalized data anywhere.
        you can check

        –CREATE TABLE
        CREATE TABLE BM_Customers (
        CustomerID int NOT NULL PRIMARY KEY CLUSTERED,
        FirstName nvarchar(100) NOT NULL,
        LastName nvarchar(100) NOT NULL,
        TaxIdNumber varchar(20) NOT NULL,
        Address nvarchar(1024) NOT NULL,
        AnnualRevenue decimal(19,2) NOT NULL,
        DateCreated datetime2(2) NOT NULL,
        ValidFrom datetime2(2) GENERATED ALWAYS AS ROW START NOT NULL,
        ValidTo datetime2(2) GENERATED ALWAYS AS ROW END NOT NULL,
        PERIOD FOR SYSTEM_TIME(ValidFrom, ValidTo)
        )
        WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.BM_CustomersHistory))

        –insert data to table
        insert into BM_Customers(CustomerID, FirstName, LastName, TaxIdNumber, Address, AnnualRevenue, DateCreated)
        VALUES (1, ‘Cristiano’, ‘Ronaldo’, 1, ‘address’, 10, GETUTCDATE()),
        (2, ‘Alistair’, ‘Overeem’, 1, ‘address’, 20, GETUTCDATE()),
        (3, ‘Brolly’, ‘Legend’, 1, ‘address’, 30, GETUTCDATE())

        –PERFORM RANDOM UPDATES
        update BM_Customers
        set Address = ‘Mars’

        update BM_Customers
        set FirstName = ‘Broly’
        WHERE FirstName = ‘Brolly’

        –CHECK DATA
        SELECT * FROM BM_Customers

        –ELIGIBLE ANSWERS SEEM TO GONE WRONG

        –E.
        SELECT CustomerID, AVG(AnnualRevenue) AS AverageAnnualRevenue, FirstName, LastName, Address, DateCreated
        FROM BM_Customers
        WHERE YEAR(DateCreated) >= 2014
        GROUP BY CustomerID, FirstName, LastName, Address, DateCreated

        –D.
        SELECT * FROM (SELECT CustomerID, FirstName, LastName, Address, AnnualRevenue, DateCreated
        FROM BM_Customers) AS BM_Customers PIVOT(AVG(AnnualRevenue)
        FOR DateCreated IN([2018])) AS PivotCustomers
        ORDER BY LastName, FirstName

        –G.
        SELECT CustomerID, FirstName, LastName, TaxIdNumber, Address, ValidFrom, ValidTo
        FROM BM_Customers
        FOR SYSTEM_TIME BETWEEN ‘2018-01-01 00:00:00.000000’ AND ‘2019-01-01 00:00:00.000000’

        –H.
        SELECT CustomerID, FirstName, LastName, TaxIdNumber, Address, ValidFrom, ValidTo
        FROM BM_Customers
        WHERE DateCreated BETWEEN ‘20180101’ AND ‘20181231’

        –DROP TABLES
        ALTER TABLE BM_Customers
        SET (SYSTEM_VERSIONING = OFF)
        ALTER TABLE BM_Customers
        DROP PERIOD FOR SYSTEM_TIME

        DROP TABLE BM_Customers
        DROP TABLE dbo.BM_CustomersHistory




        1



        0
  1. 113 says:

    D is not a correct pivot query. the right one should be
    select CustomerId,[2014]
    from
    (select CustomerId, datename(year,DateCreated) DateCreated , AnnualRevenue from BM_Customers) AS BM_Cust
    PIVOT (
    SUM(AnnualRevenue) FOR DateCreated in ([2014]) — sum or avg
    ) as pivottable;
    i do not find any right answer. it could be E if >=2014 was = 2014




    4



    1

Leave a Reply