Querying Microsoft SQL Server 2012 v17.0

Page:    1 / 11   
Total 165 questions Expand All

You develop three Microsoft SQL Server 2012 databases named Database1, Database2,
and Database3. You have permissions on both Database1 and Database2.
You plan to write and deploy a stored procedure named dbo.usp_InsertEvent in
Database3. dbo.usp_InsertEvent must execute other stored procedures in the other
databases.
You need to ensure that callers that do not have permissions on Database1 or Database2
can execute the stored procedure.
Which Transact-SQL statement should you use?

  • A. USE Database2
  • B. EXECUTE AS OWNER
  • C. USE Database1
  • D. EXECUTE AS CALLER


Answer : B

Reference: http://msdn.microsoft.com/en-us/library/ms188354.aspx Reference: http://blog.sqlauthority.com/2007/10/06/sql-server-executing-remote-stored- procedure-callingstored-procedure-on-linked-server/

Question discussion

A table named Profits stores the total profit made each year within a territory. The Profits
table has columns named Territory, Year, and Profit.
You need to create a report that displays the profits made by each territory for each year
and its previous year.
Which Transact-SQL query should you use?

  • A. SELECT Territory, Year, Profit, LEAD(Profit, 1, 0) OVER (PARTITION BY Territory ORDER BY Year) AS PrevProfit FROM Profits
  • B. SELECT Territory, Year, Profit, LAG(Profit, 1, 0) OVER (PARTITION BY Year ORDER BY Territory) AS PrevProfit FROM Profits
  • C. SELECT Territory, Year, Profit, LAG(Profit, 1, 0) OVER (PARTITION BY Territory ORDER BY Year) AS PrevProfit FROM Profits
  • D. SELECT Territory, Year, Profit, LEAD(Profit, 1, 0) OVER (PARTITION BY Year ORDER BY Territory) AS PrevProfit FROM Profits


Answer : C

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

Question discussion

You have a database named SALES that stored the sales data and the salespeople for
your company.
You need to create a function that is passed a ProductID and then returns a list of
SalesOrderID values for orders that must be associated to a salesperson in the future. The
function must be able to return multiple SalesOrderID values.
Part of the correct Transact-SQL has been provided in the answer area below. Enter the
code in the answer area that resolves the problem and meets the stated goals or
requirements. You can add code within the code that has been provided as well as below
it.



Use the Check Syntax button to verify your work. Any syntax or spelling errors will be
reported by line and character position.



Answer : WHERE header.SalesPersonID IS NULL

Explanation: On line 8 add: IS NULL to get: CREATE FUNCTION dbo.OrdersWithNoSalesPerson(@ProductID INT) RETURNS AS header.SalesOrderID FROM Sales.SalesOrderDetail detail INNER JOIN Sales.SalesOrderHeader header on header.SalesOrderID = detail.SalesOrderID WHERE header.SalesPersonID IS NULL AND detail.ProductID = @ProductID; GO Note: IS NULL determines whether a specified expression is NULL. If the value of expression is NULL, IS NULL returns TRUE; otherwise, it returns FALSE. To determine whether an expression is NULL, use IS NULL or IS NOT NULL instead of comparison operators (such as = or !=). Comparison operators return UNKNOWN when either or both arguments are NULL. References:https://msdn.microsoft.com/en-us/library/ms188795.aspx

Question discussion

You are a database developer at an independent software vendor. You create stored
procedures that contain proprietary code.
You need to protect the code from being viewed by your customers.
Which stored procedure option should you use?

  • A. ENCRYPTBYKEY
  • B. ENCRYPTION
  • C. ENCRYPTBYPASSPHRASE
  • D. ENCRYPTBYCERT


Answer : B

Reference: http://technet.microsoft.com/en-us/library/bb510663.aspx Reference: http://technet.microsoft.com/en-us/library/ms174361.aspx Reference: http://msdn.microsoft.com/en-us/library/ms187926.aspx Reference: http://technet.microsoft.com/en-us/library/ms190357.aspx Reference: http://technet.microsoft.com/en-us/library/ms188061.aspx

Question discussion

You use Microsoft SQL Server 2012 to create a stored procedure as shown in the following
code segment. (Line numbers are included for reference only.)


The procedure can be called within other transactions.
You need to ensure that when the DELETE statement from the
HumanResourcesJobCandidate table succeeds, the modification is retained even if the
insert into the Audit.Log table fails.
Which code segment should you add to line 14?

  • A. IF @@TRANCOUNT = 0
  • B. IF (XACT_STATE ( ) ) = 0
  • C. IF (XACT_STATE ( ) ) = 1
  • D. IF @@TRANCOUNT = l


Answer : C

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

Question discussion

Your application contains a stored procedure for each country. Each stored procedure
accepts an employee identification number through the @EmpID parameter.
You plan to build a single process for each employee that will execute the stored procedure
based on the country of residence.
Which approach should you use?

  • A. A recursive stored procedure
  • B. Trigger
  • C. An UPDATE statement that includes CASE
  • D. Cursor
  • E. The foreach SQLCLR statement


Answer : D

Question discussion

Your database contains a table named Products that has columns named ProductID and
Name.
You want to write a query that retrieves data from the Products table sorted by Name listing
15 rows at a time.
You need to view rows 31 through 45.
Which Transact-SQL query should you create?


A) Option A
B) Option B
C) Option C
D) Option D



Answer : C

Explanation: The OFFSET-FETCH clause provides you with an option to fetch only a window or page of results from the result set. OFFSET-FETCH can be used only with the ORDER BY clause. Example: Skip first 10 rows from the sorted resultset and return next 5 rows. SELECT First Name + ' ' + Last Name FROM Employees ORDER BY First Name OFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY; References: https://technet.microsoft.com/en-us/library/gg699618(v=sql.110).aspx

Question discussion

You use Microsoft SQL Server 2012 to develop a database application.
You need to create an object that meets the following requirements:
? Takes an input parameter
? Returns a table of values
? Can be referenced within a view
Which object should you use?

  • A. inline table-valued function
  • B. user-defined data type
  • C. stored procedure
  • D. scalar-valued function


Answer : A

Question discussion

You have a database application that uses Microsoft SQL Server 2012. You have a query
named Query1 that returns four columns from a frequently updated table that has a
clustered index. Three of the columns are referenced in the WHERE clause of the query.
The three columns are part of a non-clustered index. The fourth column is not referenced in
the WHERE clause.
Users report that the application begins to run slowly. You determine that the root cause for
the performance issue is Query1.
You need to optimize the statement.
What should you do?

  • A. Add a HASH hint to the query.
  • B. Add a LOOP hint to the query.
  • C. Add a FORCESEEK hint to the query.
  • D. Add an INCLUDE clause to the index.
  • E. Add a FORCESCAN hint to the Attach query.
  • F. Add a columnstore index to cover the query.
  • G. Enable the optimize for ad hoc workloads option.
  • H. Cover the unique clustered index with a columnstore index.
  • I. Include a SET FORCEPLAN ON statement before you run the query.
  • J. Include a SET STATISTICS PROFILE ON statement before you run the query. K. Include a SET STATISTICS SHOWPLAN_XML ON statement before you run the query. L. Include a SET TRANSACTION ISOLATION LEVEL REPEATABLE READ statement before you run the query. M. Include a SET TRANSACTION ISOLATION LEVEL SNAPSHOT statement before you run the query. N. Include a SET TRANSACTION ISOLATION LEVEL SERIALIZABLE statement before you run the query.


Answer : K

Explanation: SET SHOWPLAN_XML (Transact-SQL) causes SQL Server not to execute Transact-SQL statements. Instead, SQL Server returns detailed information about how the statements are going to be executed in the form of a well-defined XML document Incorrect: Not F: Columnstore indexes in the SQL Server Database Engine can be used to significantly speed-up the processing time of common data warehousing queries. Typical data warehousing workloads involve summarizing large amounts of data. But in this question the query is run on a table that is updated frequently, not a warehousing table. Reference: SET SHOWPLAN_XML (Transact-SQL) https://msdn.microsoft.com/en-us/library/ms187757.aspx

Question discussion

You develop a Microsoft SQL Server 2012 database that contains a table named Products.
The Products table has the following definition:


You need to create an audit record only when either the RetailPrice or WholeSalePrice
column is updated.
Which Transact-SQL query should you use?

  • A. CREATE TRIGGER TrgPriceChange ON Products FOR UPDATE AS IF CCLUMNS_CHANGED(RetailPrice, WholesalePrice) - - Create Audit Records
  • B. CREATE TRIGGER TrgPriceChange ON Products FOR UPDATE AS IF EXISTS(SELECT RetailPrice from inserted) OR EXISTS (SELECT WholeSalePnce FROM inserted) - - Create Audit Records
  • C. CREATE TRIGGER TrgPriceChange ON Products FOR UPDATE AS IF COLUMNS_UPDATED(RetailPrice, WholesalePrice) - - Create Audit Records
  • D. CREATE TRIGGER TrgPriceChange ON Products FOR UPDATE AS IF UPDATE(RetailPrice) OR UPDATE(WholeSalePrice) - - Create Audit Records


Answer : D

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

Question discussion

You have a SQL Server database named CUSTOMERS.
You need to sign a stored procedure named SelectCustomers in the CUSTOMERS
database.
Which four statements should you execute in sequence? To answer, move the appropriate
statements from the list of statements to the answer area and arrange them in the correct
order.




Answer :

Explanation:

There are four steps involved in signing a module: References:https://msdn.microsoft.com/en-us/library/bb669102(v=vs.110).aspx

Question discussion

You administer a Microsoft SQL Server 2012 database named ContosoDb. Tables are
defined as shown in the exhibit. (Click the Exhibit button.)


You need to display rows from the Orders table for the Customers row having the
CustomerId value set to 1 in the following XML format.

Which Transact-SQL query should you use?

  • A. SELECT OrderId, OrderDate, Amount, Name, Country FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId WHERE Customers.CustomerId = 1 FOR XML RAW
  • B. SELECT OrderId, OrderDate, Amount, Name, Country FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId WHERE Customers=CustomerId = 1 FOR XML RAW, ELEMENTS
  • C. SELECT OrderId, OrderDate, Amount, Name, Country FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId WHERE Customers.CustomerId = 1 FOR XML AUTO
  • D. SELECT OrderId, OrderDate, Amount, Name, Country FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId WHERE Customers.CustomerId = 1 FOR XML AUTO, ELEMENTS
  • E. SELECT Name, Country, OrderId, OrderDate, Amount FROM Orders INNER JOIN Customers ON Orders.CustomerId= Customers.CustomerId WHERE Customers.CustomerId = 1 FOR XML AUTO
  • F. SELECT Name, Country, OrderId, OrderDate, Amount FROM Orders INNER JOIN Customers ON Orders.CustomerId= Customers.CustomerId WHERE Customers.CustomerId = 1 FOR XML AUTO, ELEMENTS
  • G. SELECT Name AS '@Name', Country AS '@Country', OrderId, OrderDate, Amount FROM Orders INNER JOIN Customers ON Orders.CustomerId= Customers.CustomerId WHERE Customers.CustomerId = 1 FOR XML PATH ('Customers')
  • H. SELECT Name AS 'Customers/Name', Country AS 'Customers/Country', OrderId, OrderDate, Amount FROM Orders INNER JOIN Customers ON Orders.CustomerId= Customers.CustomerId WHERE Customers.CustomerId = 1 FOR XML PATH ('Customers')


Answer : C

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

Question discussion

You administer a Microsoft SQL Server 2012 server. You plan to deploy new features to an
application. You need to evaluate existing and potential clustered and non-clustered
indexes that will improve performance.
What should you do?

  • A. Query the sys.dm_db_index_usage_stats DMV.
  • B. Query the sys.dm_db_missing_index_details DMV.
  • C. Use the Database Engine Tuning Advisor.
  • D. Query the sys.dm_db_missing_index_columns DMV.


Answer : C

Question discussion

You create a table that has the StudentCode, SubjectCode, and Marks columns to record
mid-year marks for students. The table has marks obtained by 50 students for various
subjects.
You need to ensure that the following requirements are met:
? Students must be ranked based on their average marks.
? If one or more students have the same average, the same rank must be given to
these students.
? Consecutive ranks must be skipped when the same rank is assigned.
Which Transact-SQL query should you use?

  • A. SELECT StudentCode as Code, RANK() OVER(ORDER BY AVG (Marks) DESC) AS Value FROM StudentMarks GROUP BY StudentCode
  • B. SELECT Id, Name, Marks, DENSE_RANK() OVER(ORDER BY Marks DESC) AS Rank FROM StudentMarks
  • C. SELECT StudentCode as Code, DENSE_RANK() OVER(ORDER BY AVG (Marks) DESC) AS Value FROM StudentMarks GROUP BY StudentCode
  • D. SELECT StudentCode as Code, NTILE(2) OVER(ORDER BY AVG (Marks) DESC) AS Value FROM StudentMarks GROUP BY StudentCode
  • E. SELECT StudentCode AS Code,Marks AS Value FROM ( SELECT StudentCode, Marks AS Marks, RANK() OVER(PARTITION BY SubjectCode ORDER BY Marks ASC) AS Rank FROM StudentMarks) tmp WHERE Rank = 1
  • F. SELECT StudentCode AS Code,Marks AS Value FROM ( SELECT StudentCode, Marks AS Marks, RANK() OVER(PARTITION BY SubjectCode ORDER BY Marks DESC) AS Rank FROM StudentMarks) tmp WHERE Rank = 1
  • G. SELECT StudentCode AS Code,Marks AS Value FROM ( SELECT StudentCode, Marks AS Marks, RANK() OVER(PARTITION BY StudentCode ORDER BY Marks ASC) AS Rank FROM StudentMarks) tmp WHERE Rank = 1
  • H. SELECT StudentCode AS Code,Marks AS Value FROM ( SELECT StudentCode, Marks AS Marks, RANXO OVER(PARTITION BY StudentCode ORDER BY Marks DESC) AS Rank FROM StudentMarks) tmp WHERE Rank = 1


Answer : A

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

Question discussion

You use Microsoft SQL Server 2012 database to develop a shopping cart application.
You need to rotate the unique values of the ProductName field of a table-valued expression
into multiple columns in the output.
Which Transact-SQL operator should you use?

  • A. CROSS JOIN
  • B. CROSS APPLY
  • C. PIVOT
  • D. UNPIVOT


Answer : C

Explanation: http://technet.microsoft.com/en-us/library/ms177634.aspx

Question discussion

Page:    1 / 11   
Total 165 questions Expand All

Talk to us!


Have any questions or issues ? Please dont hesitate to contact us