Test Flashcards

1
Q

You develop a Microsoft SQL Server 2012 server database that supports an application.The application contains a table that has the following definition:<br></br>CREATE TABLE Inventory (<br></br>ItemID int NOT NULL PRIMARY KEY,<br></br>ItemsInStore int NOT NULL,<br></br>ItemsInWarehouse int NOT NULL)<br></br>You need to create a computed column that returns the sum total of the ItemsInStore andItemsInWarehouse values for each row. The new column is expected to be queried heavily, and you needto be able to index the column.<br></br>Which Transact-SQL statement should you use?<br></br>A. ALTER TABLE Inventory ADD TotalItems AS ItemslnStore + ItemsInWarehouse<br></br>B. ALTER TABLE Inventory ADD TotalItems AS ItemsInStore + ItemsInWarehouse PERSISTED<br></br>C. ALTER TABLE Inventory ADD TotalItems AS SUM(ItemsInStore, ItemsInWarehouse) PERSISTED<br></br>D. ALTER TABLE Inventory ADD TotalItems AS SUM(ItemsInStore, ItemsInWarehouse)

A

B.

ALTER TABLE Inventory ADD TotalItems

AS

ItemsInStore + ItemsInWarehouse PERSISTED

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

<span>You need to create an audit record only when either the MobileNumber or HomeNumber column isupdated.</span>

<span>Which Transact-SQL query should you use?<br></br> A. CREATE TRIGGER TrgPhoneNumberChange<br></br> ON Customers FOR UPDATE AS IF COLUMNS_UPDATED (HomeNumber, MobileNumber) - - Create Audit Records<br></br> B. CREATE TRIGGER TrgPhoneNumberChange ON Customers FOR UPDATE AS IF EXISTS( SELECT<br></br> HomeNumber FROM inserted) OR EXISTS (SELECT MobileNumber FROM inserted) - - Create Audit Records<br></br> C. CREATE TRIGGER TrgPhoneNumberChange ON Customers FOR UPDATE AS IF COLUMNS_CHANGED (HomeNumber, MobileNumber) - - Create Audit Records<br></br> D. CREATE TRIGGER TrgPhoneNumberChange ON Customers FOR UPDATE AS IF UPDATE<br></br> (HomeNumber) OR UPDATE (MobileNumber)<br></br> - - Create Audit Records</span>

A

Answer: D.

CREATE TRIGGER TrgPhoneNumberChange ON Customers FOR UPDATE AS IF UPDATE<br></br> (HomeNumber) OR UPDATE (MobileNumber)<br></br> - - Create Audit Records

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

2 tables named SavingAccounts andLoanAccounts. Both tables have a column named AccountNumber of the nvarchar data type. You use athird table named Transactions that has columns named TransactionId AccountNumber, Amount, andTransactionDate. You need to ensure that when multiple records are inserted in the Transactions table,only the records that have a valid AccountNumber in the SavingAccounts or LoanAccounts are inserted.Which Transact-SQL statement should you use?
A. CREATE TRIGGER TrgValidateAccountNumber ON Transactions<br></br> INSTEAD OF INSERT<br></br> AS<br></br> BEGIN<br></br> INSERT INTO Transactions<br></br> SELECT TransactionID,AccountNumber,Amount,TransactionDate<br></br> FROM inserted WHERE AccountNumber IN<br></br> (SELECT AccountNumber FROM LoanAccounts<br></br> UNION SELECT AccountNumber FROM SavingAccounts))<br></br> END<br></br> B. CREATE TRIGGER TrgValidateAccountNumber ON Transactions<br></br> FOR INSERT<br></br> AS<br></br> BEGIN<br></br> INSERT INTO Transactions<br></br> SELECT TransactionID,AccountNumber,Amount,TransactionDate<br></br> FROM inserted WHERE AccountNumber IN<br></br> (SELECT AccountNumber FROM LoanAccounts<br></br> UNION SELECT AccountNumber FROM SavingAccounts))<br></br> END<br></br> C. CREATE TRIGGER TrgValidateAccountNumber ON Transactions<br></br> INSTEAD OF INSERT<br></br> AS<br></br> BEGIN<br></br> IF EXISTS (<br></br> SELECT AccountNumber FROM inserted EXCEPT<br></br> (SELECT AccountNumber FROM LoanAccounts<br></br> UNION SELECT AccountNumber FROM SavingAccounts))<br></br> BEGIN<br></br> ROLLBACK TRAN<br></br> END<br></br> END<br></br> D. CREATE TRIGGER TrgValidateAccountNumber ON Transactions<br></br> FOR INSERT<br></br> AS<br></br> BEGIN<br></br> IF EXISTS (<br></br> SELECT AccountNumber FROM inserted EXCEPT<br></br> (SELECT AccountNumber FROM LoanAccounts<br></br> UNION SELECT AccountNumber FROM SavingAccounts))<br></br> BEGIN<br></br> ROLLBACK TRAN<br></br> END<br></br> END

A

A.

CREATE TRIGGER TrgValidateAccountNumber ON Transactions<br></br> INSTEAD OF INSERT<br></br> AS<br></br> BEGIN<br></br> INSERT INTO Transactions<br></br> SELECT TransactionID,AccountNumber,Amount,TransactionDate FROM inserted<br></br> WHERE AccountNumber IN<br></br> (SELECT AccountNumber FROM LoanAccounts<br></br> UNION<br></br> SELECT AccountNumber FROM SavingAccounts)<br></br> END

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You develop a Microsoft SQL Server 2012 database.<br></br> You create a view that performs the following tasks:

  • Joins 8 tables that contain up to 500,000 records each.
  • Performs aggregations on 5 fields.

The view is frequently used in several reports. You need to improve the performance of the reports.<br></br> What should you do?<br></br> A. Convert the view into a table-valued function.<br></br> B. Convert the view into a Common Table Expression (CTE).<br></br> C. Convert the view into an indexed view.<br></br> D. Convert the view into a stored procedure and retrieve the result from the stored procedure into atemporary table.

A

Answer: C

C. Convert the view into an indexed view

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You need to ensure that the CustomerId column in the Orders table contains only values that exist in the CustomerId column of the Customer table. Which Transact-SQL statement should you use?
A. ALTER TABLE Orders<br></br>ADD CONSTRAINT FX_Orders_CustomerID FOREIGN KEY (CustomerId) REFERENCES Customer (CustomerId)<br></br>B. ALTER TABLE Customer<br></br>ADD CONSTRAINT FK_Customer_CustomerID FOREIGN KEY {CustomerID) REFERENCES Orders (CustomerId)<br></br>C. ALTER TABLE Orders<br></br>ADD CONSTRAINT CK_Crders_CustomerID CHECK (CustomerId IN (SELECT CustomerId FROM Customer))<br></br>D. ALTER TABLE Customer<br></br>ADD OrderId INT NOT NULL;<br></br>ALTER TABLE Customer<br></br>ADD CONSTRAINT FK_Customer_OrderID FOREIGN KEY (CrderlD) REFERENCES Orders(CrderlD);<br></br>E. ALTER TABLE Orders<br></br>ADD CONSTRAINT PK Orders CustomerId PRIMARY KEY (CustomerID)

A

Answer: A

ALTER TABLE Orders
ADD CONSTRAINT FX_Orders_CustomerID FOREIGN KEY (CustomerId) REFERENCES Customer (CustomerId)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

You need to ensure that users can update only the phone numbers and email addresses by using thisview.<br></br>What should you do?<br></br>A. Alter the view. Use the EXPAND VIEWS query hint along with each SELECT statement.<br></br>B. Create an INSTEAD OF UPDATE trigger on the view.<br></br>C. Drop the view. Re-create the view by using the SCHEMABINDING clause, and then create an index on<br></br>the view.<br></br>D. Create an AFTER UPDATE trigger on the view.

A

Answer: B

B. Create an INSTEAD OF UPDATE trigger on the view.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

CREATE VIEW vOrders WITH SCHEMABINDING<br></br> AS<br></br> SELECT o.ProductID o.OrderDate,<br></br> SUM(od.UnitPrice * od.OrderQty) AS Amount<br></br> FROM OrderDetails AS od INNER JOIN<br></br> Orders as o on od.OrderID = o.OrderID<br></br> Where od.SalesOrderID = o.SalesOrderID<br></br> Group by o.OrderDate,o.ProductID

You need to ensure that users are able to modify data by using the view.<br></br> What should you do?<br></br> A. Create an AFTER trigger on the view.<br></br> B. Modify the view to use the WITH VIEW_METADATA clause.<br></br> C. Create an INSTEAD OF trigger on the view.<br></br> D. Modify the view to an indexed view.

A

Answer: <strong>C</strong>

<strong>C</strong>. Create an INSTEAD OF trigger on the view.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

You have a view that was created by using the following code:

<span>CREATE VIEW Sales.OrderByTerritory AS</span>

<span>SELECT OrderID, OrderDate, SalesTerritoryID, TotalDue FROM Sales.Orders</span>

You need to create an inline table-valued function named Sales.fn_OrdersByTerritory, which must meet<br></br> the following requirements:<br></br> - Accept the @T integer parameter.<br></br> - Use one-part names to reference columns.<br></br> - Filter the query results by SalesTerritoryID.<br></br> - Return the columns in the same order as the order used in OrdersByTerritoryView.<br></br> Which code segment should you use? To answer, type the correct code in the answer area.

A

CREATE FUNCTION Sales.fn_OrdersByTerritory (@T int)<br></br> RETURNS TABLE<br></br> AS<br></br> RETURN<br></br> (<br></br> SELECT OrderID,OrderDate,SalesTerrirotyID,TotalDue<br></br> FROM Sales.OrdersByTerritory<br></br> WHERE SalesTerritoryID = @T<br></br> )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

You need to create a table named Sales.OrderDetails on the new server. Sales.OrderDetails must meet the following requirements:

  • Write the results to a disk.
  • Contain a new column named LineItemTotal that stores the product of ListPrice and Quantity for each row.
  • The code must NOT use any object delimiters.

The solution must ensure that LineItemTotal is stored as the last column in the table. Which code segment should you use? To answer, type the correct code in the answer area.

A

Answer:
CREATE TABLE Sales.OrderDetails (
ListPrice money not null,
Quantity int not null,
LineItemTotal as (ListPrice * Quantity) PERSISTED)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

You have an XML schema collection named <strong>Sales.InvoiceSchema</strong>. You need to declare a variable ofthe XML type named XML1. The solution must ensure that XML1 is validated by usingSales.InvoiceSchema.Which code segment should you use? To answer, type the correct code in the answer area.

A

Answer:

DECLARE @XML1 XML(Sales.InvoiceSchema)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

You need to create a query that returns a list of products from Sales.ProductCatalog.The solution must meet the following requirements:

  • UnitPrice must be returned in descending order
  • The query must use two-part names to reference the table
  • The query must use the RANK function to calculate the results
  • The query must return the ranking of rows in a column named PriceRank
  • The list must display the columns in the order that they are defined in the table.
  • PriceRank must appear last.
A

<strong>SELECTProductCatalog.CatID, ProductCatalog.CatName, ProductCatalog.ProductID, ProductCatalog.ProdName, ProductCatalog.UnitPrice</strong><br></br> RANK<strong>() </strong>OVER<strong> (</strong>ORDER BY<strong> ProductCatalog.UnitPrice DESC) AS </strong>PriceRank<br></br> FROM <strong>Sales.ProductCatalog</strong><br></br> ORDER BY<strong> ProductCatalog.UnitPrice DESC</strong>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

You have a parameter named @Count that uses the int data type. App1 is configured to pass @Count to a stored procedure. You need to create a stored procedure named usp_Customers for App1.

Usp_Customers must meet the following requirements:

  • NOT use object delimiters
  • Minimize sorting and counting.
  • Return only the last name of each customer in alphabetical order
  • Return only the number of rows specified by the @Count parameter.
  • The solution must NOT use BEGIN and END statements.
A
  • *Answer**:
  • *CREATE PROCEDURE** usp_Customers @Count int
  • *AS**
  • *SELECT TOP**(@Count) Customers.LastName
  • *FROM** Customers
  • *ORDER BY** Customers.LastName
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Procedure1 has a single parameter named Parameter1.<br></br>Parameter1 uses the varchar type and is configured to pass the specific date to Procedure1. A DBAdiscovers that OrderDate is not being compared correctly to Parameter1 after the data type<br></br>of the column is changed to datetime.You need to update the SELECT statement to meet the following requirements

  • The code must NOT use aliases.
  • The code must NOT use object delimiters.
  • The objects called in Procedure1 must be able to be resolved by all users.
  • OrderDate must be compared to Parameter1 after the data type of Parameter1 is changed to datetime
A

Answer:
SELECT Orders.OrderID

FROM Orders

WHERE Orders.OrderDate > CONVERT(datetime,@Parameter1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

You use Microsoft SQL Server 2012 database to develop a shopping cart application. You need to
invoke a table-valued function for each row returned by a query. Which Transact-SQL operator should you use?

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

Answer: **D **CROSSAPPLY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

You need to write a query that displays the following details:<br></br> -Total sales made by <strong>sales people, year, city, and country</strong><br></br> - <strong>Sub totals </strong>only at the <strong>city</strong> level and <strong>country </strong>level<br></br> - A grand total of the sales amount<br></br> Which Transact-SQL query should you use?

A. SELECT SalesPerson.Name, Country, City,<br></br> DatePart(yyyy, SaleDate) AS Year, Sum(Amount) AS Total<br></br> FROM Sale INNER JOIN SalesPerson<br></br> ON Sale.SalesPersonID = SalesPerson.SalesPersonID<br></br> GROUP BY GROUPING SETS((SalesPerson.Name, Country, City, DatePart(yyyy,SaleDate)), (Country, City), (Country), ())

B.SELECT SalesPerson.Name, Country, City,<br></br> DatePart(yyyy, SaleDate) AS Year, Sum(Amount) AS Total<br></br> FROM Sale INNER JOIN SalesPerson<br></br> ON Sale.SalesPersonID = SalesPerson.SalesPersonID<br></br> GROUP BY CUBE(SalesPerson.Name, Country, City, DatePart(yyyy, SaleDate))

C. SELECT SalesPerson.Name, Country, City,<br></br> DatePart(yyyy, SaleDate) AS Year, Sum(Amount) AS Total<br></br> FROM Sale INNER JOIN SalesPerson<br></br> ON Sale.SalesPersonID = SalesPerson.SalesPersonID<br></br> GROUP BY CUBE(SalesPerson.Name, DatePart(yyyy, SaleDate), City, Country)

D. SELECT SalesPerson.Name, Country, City,<br></br> DatePart(yyyy, SaleDate) AS Year, Sum(Amount) AS Total<br></br> FROM Sale INNER JOIN SalesPerson<br></br> ON Sale.SalesPersonID = SalesPerson.SalesPersonID

A

Answer: A

SELECT SalesPerson.Name, Country, City,
DatePart(yyyy, SaleDate) AS Year, Sum(Amount) AS Total
FROM Sale INNER JOIN SalesPerson
ON Sale.SalesPersonID = SalesPerson.SalesPersonID
GROUP BY GROUPING SETS((SalesPerson.Name, Country, City, DatePart(yyyy, SalesDate)), (Country, City), (Country), ())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

You are developing a database that will contain price information. You need to store the prices that include a fixed precision and a scale of six digits. Which data type should you use?

A. Float
B. Money
C. Smallmoney
D. Numeric

A

Answer: D Numeric

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

You administer a Microsoft SQL Server database that supports a banking transaction managementapplication. You need to retrieve a list of account holders who live in cities that do not have a branchlocation.<br></br> Which Transact-SQL query or queries should you use? (Choose all that apply.)<br></br> A. SELECT AccountHolderIDFROM AccountHolder<br></br> WHERE CityID NOT IN (SELECT CityID FROM BranchMaster)<br></br> B. SELECT AccountHolderIDFROM AccountHolder<br></br> WHERE CityID <> ALL (SELECT CityID FROM BranchMaster)<br></br> C. SELECT AccountHolderlDFROM AccountHolder<br></br> WHERE CityID <> SOME (SELECT CityID FROM BranchMaster)<br></br> D. SELECT AccountHolderIDFROM AccountHolder<br></br> WHERE CityID <> ANY (SELECT CityID FROM BranchMaster)

A

Answer: A, B

A. SELECT AccountHolderIDFROM AccountHolder<br></br> WHERE CityID NOT IN (SELECT CityID FROM BranchMaster)<br></br> B. SELECT AccountHolderIDFROM AccountHolder<br></br> WHERE CityID <> ALL (SELECT CityID FROM BranchMaster)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

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

A. USE Database2<br></br> B. EXECUTE AS OWNER<br></br> C. USE Database1<br></br> D. EXECUTE AS CALLER

A

Answer: B Execute As Owner

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

You develop a Microsoft SQL Server 2012 database that contains tables named Customers andOrders. The tables are related by a column named CustomerId . You need to create a query that meetsthe following requirements:<br></br> - Returns the CustomerName for all customers and the OrderDate for any orders that they have placed.<br></br> - Results must not include customers who have not placed any orders.

A. SELECT CustomerName, OrderDateFROM Customers<br></br> LEFT OUTER JOIN OrdersON Customers.CuscomerlD = Orders.CustomerId<br></br> B. SELECT CustomerName, OrderDateFROM Customers<br></br> RIGHT OUTER JOIN OrdersON Customers.CustomerID = Orders.CustomerId<br></br> C. SELECT CustomerName, OrderDateFROM Customers<br></br> CROSS JOIN OrdersON Customers.CustomerId = Orders.CustomerId<br></br> D. SELECT CustomerName, OrderDateFROM Customers<br></br> JOIN OrdersON Customers.CustomerId = Orders.CustomerId

A

Answer: D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

You develop a Microsoft SQL Server 2012 database.You need to create a batch process that meets the following requirements:

  • Status information must be logged to a status table.
  • If the status table does not exist at the beginning of the batch, it must be created.

A. Scalar user-defined function<br></br> B. Inline user-defined function<br></br> C. Table-valued user-defined function<br></br> D. Stored procedure

A

Answer: D.Stored Procedure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

You use a Microsoft SQL Server 2012 database that contains a table named BlogEntry that has the<br></br> following columns:<br></br> Id BigInt<br></br> EntryDateTime datetime<br></br> Summary nvarchar(max)

Id is the Primary Key.<br></br> You need to append the “This is in a draft stage” string to the Summary column of the recent 10 entries based on the values in EntryDateTime.

A. UPDATE TOP(10) BlogEntry<br></br> SET Summary.WRITE(N’ This is in a draft stage’, NULL, 0)<br></br> B. UPDATE BlogEntry<br></br> SET Summary = CAST(N’ This is in a draft stage’ as nvarchar(max))<br></br> WHERE Id IN(SELECT TOP(10) Id FROM BlogEntry ORDER BY EntryDateTime DESC)<br></br> C. UPDATE BlogEntry<br></br> SET Summary.WRITE(N’ This is in a draft stage’, NULL, 0) FROM (<br></br> SELECT TOP(10) Id FROM BlogEntry ORDER BY EntryDateTime DESC) AS s<br></br> WHERE BlogEntry.Id = s.ID<br></br> D. UPDATE BlogEntry<br></br> SET Summary.WRITE(N’ This is in a draft stage’, 0, 0)<br></br> WHERE Id IN(SELECT TOP(10) Id FROM BlogEntry ORDER BY EntryDateTime DESC)

A

Answer: D.<br></br> UPDATE BlogEntry<br></br> SET Summary.WRITE(N’ This is in a draft stage’, 0, 0)<br></br> WHERE Id IN(SELECT TOP(10) Id FROM BlogEntry ORDER BY EntryDateTime DESC)<br></br> <u><em>.WRITE(expression, @Offset, @Length)</em></u><br></br> If @offset is null, the update operation appends expression at the end of the existing expression value and @Length is ignored.<br></br> If @Length is NULL, the update operation removes all data from @Offset to the end of the expression value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How to use .WRITE?

A

.WRITE (expression,@Offset,@Length)

Specifies that a section of the value is to be modified.

  • Expression replaces @Length units starting from @Offset column.
  • Only columns of varchar(max), nvarchar(max), or varbinary(max) can be specified with this clause
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

@@ERROR

A
  • Unstructured error handling
  • Test individual statement immediately after they executed
  • TSQL records an error status of the execution result in @@ERROR.
  • @@ERROR = 0 good.
  • Capture @@ERROR in a variable and test the variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

BEGIN CATCH

________

COMMIT TRANSACTION

END CATCH

The stored procedure can be called within other transactions. You need to ensure that when the DELETE<br></br> statement from the HumanResourcesJobCandidate table succeeds, the modification is retained even if<br></br> the insert into the Audit.Log table fails.

A. IF @@TRANCOUNT = 0<br></br> B. IF (XACT_STATE ( ) ) = 0<br></br> C. IF (XACT_STATE ( ) ) = 1<br></br> D. IF @@TRANCOUNT = 1

A

Answer: C

IF (XACT_STATE ( ) ) = 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

LAG

A

Use this analytic function in a SELECT statement to compare values in the current row with values in a previous row.

LAG (scalar_expression [,offset] [,default])OVER ( [partition_by_clause] order_by_clause )

offset -The number of rows back from the current row from which to obtain a value. If not specified, the default is 1.

default -The value to return when scalar_expression at offset is NULL. If a default value is not specified, NULL is returned

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

You use Microsoft SQL Server 2012 to develop a database application. Your application sends data to<br></br> an NVARCHAR(MAX) variable named @var. You need to write a Transact-SQL statement that will find<br></br> out the success of a cast to a decimal (36, 9).

A. BEGIN TRY<br></br> SELECT convert(decimal(36,9), @var) AS Value, ‘True’ AS BadCast<br></br> END TRY<br></br> BEGIN CATCH<br></br> SELECT convert(decimal(36,9), @var) AS Value, ‘False’ AS BadCast<br></br> END CATCH<br></br> B. TRY(<br></br> SELECT convert(decimal(36,9), @var)<br></br> SELECT ‘True’ AS BadCast<br></br> )<br></br> CATCH(SELECT ‘False’ AS BadCast)<br></br> C. SELECT<br></br> CASE<br></br> WHEN convert(decimal(36,9), @var) IS NULL<br></br> THEN ‘True’<br></br> ELSE ‘False’<br></br> END<br></br> AS BadCast<br></br> D. SELECT<br></br> IIF(TRY_PARSE(@var AS decimal(36,9)) IS NULL, ‘True’, ‘False’)<br></br> AS BadCast

A

Answer: D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

You are writing a set of queries against a FILESTREAM-enabled database. You create a stored<br></br> procedure that will update multiple tables within a transaction. You need to ensure that if the stored<br></br> procedure raises a run-time error, the entire transaction is terminated and rolled back.<br></br> Which Transact-SQL statement should you include at the beginning of the stored procedure?<br></br> A. SET TRANSACTION ISOLATION LEVEL SERIALIZABLE<br></br> B. SET XACT_ABORT OFF<br></br> C. SET TRANSACTION ISOLATION LEVEL SNAPSHOT<br></br> D. SET IMPLICIT_TRANSACTIONS ON<br></br> E. SET XACT_ABORT ON<br></br> F. SET IMPLICIT TRANSACTIONS OFF

A

Answer: E

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

You have a Microsoft SQL Server 2012 database that contains tables named Customers and Orders.<br></br> The tables are related by a column named CustomerID.<br></br> You need to create a query that meets the following requirements:<br></br> - Returns the CustomerName for all customers and the OrderDate for any orders that they have placed.<br></br> - Results must include customers who have not placed any orders.<br></br> Which Transact-SQL query should you use?<br></br> A. SELECT CustomerName, OrderDate FROM Customers<br></br> RIGHT OUTER JOIN Orders<br></br> ON Customers.CustomerID = Orders.CustomerID<br></br> B. SELECT CustomerName, CrderDate FROM Customers<br></br> JOIN Orders<br></br> ON Customers.CustomerID = Orders.CustomerID<br></br> C. SELECT CustomerName, OrderDate FROM Customers<br></br> CROSS JOIN Orders<br></br> ON Customers.CustomerID = Orders.CustomerID<br></br> D. SELECT CustomerName, OrderDate FROM Customers<br></br> LEFT OUTER JOIN Orders<br></br> ON Customers.CustomerID = Orders.CustomerID

A

Answer: D

30
Q

.You create a stored procedure that will update multiple tables within a transaction. You need to ensurethat if the stored procedure raises a run-time error, the entire transaction is terminated and rolled back.Which Transact-SQL statement should you include at the beginning of the stored procedure?<br></br> A. SET XACT_ABORT ON<br></br> B. SET ARITHABORT ON<br></br> C. TRY<br></br> D. BEGIN<br></br> E. SET ARITHABORT OFF<br></br> F. SET XACT_ABORT OFF

A

Answer: A

31
Q

You develop a Microsoft SQL Server 2012 database that contains a heap named OrdersHistorical. You write the following Transact-SQL query:
INSERT INTO OrdersHistorical
SELECT * FROM CompletedOrders
You need to optimize transaction logging and locking for the statement. Which table hint should you use?

A. HOLDLOCK
B. ROWLOCK
C. XLOCK
D. UPDLOCK
E. TABLOCK

A

Answer : E. TABLOCK

32
Q

You use a Microsoft SQL Server 2012 database that contains two tables named SalesOrderHeaderand SalesOrderDetail.

SELECT h.SalesOrderID, h.TotalDue, d.OrderQty From Sales.SalesOrderHeader AS h INNER JOIN Sales.SalesOrderDetail AS d ON h.SalesOrderID = d.SalesOrderID WHERE h.TotalDue > 100 AND (d.OrderQty > 5 OR d.LineTotal < 1000.00)

You discover that the performance of the query is slow. Analysis of the query plan shows table scanswhere the estimated rows do not match the actual rows for SalesOrderHeader by using an unexpectedindex on SalesOrderDetail. You need to improve the performance of the query.

A. Use a FORCESCAN hint in the query.<br></br> B. Add a clustered index on SalesOrderId in SalesOrderHeader.<br></br> C. Use a FORCESEEK hint in the query.<br></br> D. Update statistics on SalesOrderId on both tables.

A

Answer: D

Update statistics on SalesOrderId on both tables.

33
Q

Your database contains a table named Purchases. The table includes a DATETIME column named PurchaseTime that stores the date and time each purchase is made. There is a non-clustered index on
the PurchaseTime column. The business team wants a report that displays the total number of purchases
made on the current day. You need to write a query that will return the correct results in the most efficient
manner.

Which Transact-SQL query should you use?<br></br> A. SELECT COUNT()FROM Purchases<br></br> WHERE PurchaseTime = CONVERT(DATE, GETDATE())<br></br> B. SELECT COUNT()FROM Purchases<br></br> WHERE PurchaseTime = GETDATE()<br></br> C. SELECT COUNT()FROM Purchases<br></br> WHERE CONVERT(VARCHAR, PurchaseTime, 112) = CONVERT(VARCHAR, GETDATE(), 112)<br></br> D. SELECT COUNT()FROM Purchases<br></br> WHERE PurchaseTime >= CONVERT(DATE, GETDATE())<br></br> AND PurchaseTime < DATEADD(DAY, 1, CONVERT(DATE, GETDATE()))

A

Answer: D

34
Q

You develop a database for a travel application. You need to design tables and other database objects.You need to store media files in several tables. Each media file is less than 1 MB in size. The media fileswill require fast access and will be retrieved frequently.What should you do?

A. Use the CAST function.<br></br> B. Use the DATE data type.<br></br> C. Use the FORMAT function.<br></br> D. Use an appropriate collation.<br></br> E. Use a user-defined table type.<br></br> F. Use the VARBINARY data type.<br></br> G. Use the DATETIME data type.<br></br> H. Use the DATETIME2 data type.<br></br> I. Use the DATETIMEOFFSET data type.<br></br> J. Use the TODATETIMEOFFSET function

A

Answer: F

35
Q

You develop a database for a travel application. You need to design tables and other database objects.<br></br> You create a view that displays the dates and times of the airline schedules on a report. You need todisplay dates and times in several international formats.What should you do?

A. Use the CAST function.<br></br> B. Use the DATE data type.<br></br> C. Use the FORMAT function.<br></br> D. Use an appropriate collation.<br></br> E. Use a user-defined table type.<br></br> F. Use the VARBINARY data type.<br></br> G. Use the DATETIME data type.<br></br> H. Use the DATETIME2 data type.<br></br> I. Use the DATETIMEOFFSET data type.<br></br> J. Use the TODATETIMEOFFSET function.

A

Answer: C

Use the FORMAT function

36
Q

You are a database developer of a Microsoft SQL Server 2012 database. You are designing a tablethat will store Customer data from different sources. The table will include a column that contains theCustomerID from the source system and a column that contains the SourceID.<br></br>A sample of this data is as shown in the following table. You need to ensure that the table has no duplicate CustomerID within a SourceID. You also need to ensure that the data in the table is in the order of SourceID and then CustomerID.Which Transact- SQL statement should you use?

A. CREATE TABLE Customer (SourceID int NOT NULL IDENTITY, CustomerID int NOT NULL IDENTITY,<br></br>CustomerName varchar(255) NOT NULL);<br></br>B. CREATE TABLE Customer (SourceID int NOT NULL, CustomerID int NOT NULL PRIMARY KEYCLUSTERED, CustomerName varchar(255) NOT NULL);<br></br>C. CREATE TABLE Customer (SourceID int NOT NULL PRIMARY KEY CLUSTERED, CustomerID intNOT NULL UNIQUE, CustomerName varchar(255) NOT NULL);<br></br>D. CREATE TABLE Customer (SourceID int NOT NULL, CustomerID int NOT NULL, CustomerNamevarchar(255) NOT NULL, CONSTRAINT PK_Customer PRIMARY KEY CLUSTERED (SourceID,CustomerID));

A

Answer :D

CREATE TABLE Customer<br></br>(SourceID int NOT NULL,<br></br>CustomerID int NOT NULL,<br></br>CustomerName varchar(255) NOT NULL,<br></br>CONSTRAINT PK_Customer PRIMARY KEY CLUSTERED (SourceID, CustomerID));

37
Q

You have three tables that contain data for vendors, customers, and agents. You create a view that isused to look up phone numbers for these companies.The view has the following definition:

CREATE VIEW apt.cwCompanyPhoneList (Source, CompanyID, Lastname, Phone) AS<br></br> SELECT ‘Customer’ as Source, CustID, CustLastName, phone FROM apt.Customer<br></br> UNION ALL<br></br> SELECT ‘Agent’ as Source, AgentID, AgentLastName, phone FROM apt.Agent<br></br> UNION ALL<br></br> SELECT ‘Vendor’ as Source, VendID, VendLastName, phone FROM apt.Vendor

You need to ensure that users can update only the phone numbers by using this view

A. Alter the view. Use the EXPAND VIEWS query hint along with each SELECT statement.<br></br> B. Drop the view. Re-create the view by using the SCHEMABINDING clause, and then create an index onthe view.<br></br> C. Create an AFTER UPDATE trigger on the view.<br></br> D. Create an INSTEAD OF UPDATE trigger on the view.

A

Answer: D

Create an INSTEAD OF UPDATE trigger on the view.

38
Q

You develop a Microsoft SQL Server 2012 database that contains a table named Product. You need to create an audit record only when either the RetailPrice or WholeSalePrice column is updated.

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

A

Answer: D

CREATE TRIGGER TrgPriceChange ON Products FOR UPDATE AS IF UPDATE(RetailPrice) OR<br></br> UPDATE(WholeSalePrice)<br></br> - - Create Audit Records

39
Q

You develop a Microsoft SQL Server 2012 server database that supports an application.The application contains a table that has the following definition:<br></br> CREATE TABLE Inventory<br></br> (ItemID int NOT NULL PRIMARY KEY,<br></br> ItemsInStore int NOT NULL,<br></br> ItemsInWarehouse int NOT NULL)<br></br> You need to create a computed column that returns the sum total of the ItemsInStore andItemsInWarehouse values for each row.

A. ALTER TABLE Inventory<br></br> ADD TotalItems AS ItemsInStore + ItemsInWarehouse<br></br> B. ALTER TABLE Inventory<br></br> ADD ItemsInStore - ItemsInWarehouse = TotalItems<br></br> C. ALTER TABLE Inventory<br></br> ADD TotalItems = ItemsInStore + ItemsInWarehouse<br></br> D. ALTER TABLE Inventory<br></br> ADD TotalItems AS SUM(ItemsInStore, ItemslnWarehouse);

A

Answer: A

40
Q

Triggers

A

A special kind of stored procedure that automatically executes when an event occurs in the database server.

  • DML - INSERT, UPDATE, or DELETE statements on a table or view
  • DDL - CREATE, ALTER, and DROP statements
  • Login - When a user sessions is being established
41
Q

You develop a Microsoft SQL Server 2012 database. You create a view from the Orders and<br></br> OrderDetails tables by using the following definition.

CREATE VIEW vOrders WITH SCHEMABINDING AS SELECT o.ProductID, o.OrderDate, SUM(od.UnitPrice * od.OrderQty) AS Amount FROM OrderDetails AS od INNER JOIN Orders AS o ON od.OrderID = o.OrderID WHERE od.SalesOrderID = o.SalesOrderID GROUP BY o.OrderDate, o.ProductID;

You need to improve the performance of the view by persisting data to disk.<br></br> What should you do?<br></br> A. Create an INSTEAD OF trigger on the view.<br></br> B. Create an AFTER trigger on the view.<br></br> C. Modify the view to use the WITH VIEW_METADATA clause.<br></br> D. Create a clustered index on the view.

A

Answer: D

42
Q

Your database contains tables named Products and ProductsPriceLog. The Products table contains columns named ProductCode and Price. The ProductsPriceLog table contains columns named ProductCode, OldPrice, and NewPrice. The ProductsPriceLog table stores the previous price in the OldPrice column and the new price in the NewPrice column. You need to increase the values in the Price column of all products in the Products table by 5 percent. You also need to log the changes to the ProductsPriceLog table.Which Transact-SQL query should you use?

A. UPDATE Products SET Price = Price * 1.05<br></br> OUTPUT inserted.ProductCode, deleted.Price, inserted.Price<br></br> INTO ProductsPriceLog(ProductCode, OldPrice, NewPrice)<br></br> B. UPDATE Products SET Price = Price * 1.05<br></br> OUTPUT inserted.ProductCode, inserted.Price, deleted.Price<br></br> INTO ProductsPriceLog(ProductCode, OldPrice, NewPrice)<br></br> C. UPDATE Products SET Price = Price * 1.05<br></br> OUTPUT inserted.ProductCode, deleted.Price, inserted.Price)<br></br> INTO ProductsPriceLog(ProductCode, OldPrice, NewPrice)<br></br> D. UPDATE Products SET Price = Price * 1.05<br></br> INSERT INTO ProductsPriceLog (ProductCode, CldPnce, NewPrice)<br></br> SELECT ProductCode, Price, Price * 1.05 FROM Products

A

Answer: A

43
Q

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?<br></br> A. SELECT Territory, Year, Profit,<br></br> LEAD(Profit, 1, 0) OVER (PARTITION BY Territory ORDER BY Year) AS<br></br> PrevProfit FROM Profits<br></br> B. SELECT Territory, Year, Profit,<br></br> LAG(Profit, 1, 0) OVER (PARTITION BY Year ORDER BY Territory) AS<br></br> PrevProfit FROM Profits<br></br> C. SELECT Territory, Year, Profit,<br></br> LAG(Profit, 1, 0) OVER (PARTITION BY Territory ORDER BY Year) AS<br></br> PrevProfit FROM Profits<br></br> D. SELECT Territory, Year, Profit,<br></br> LEAD(Profit, 1, 0) OVER (PARTITION BY Year ORDER BY Territory) AS<br></br> PrevProfit FROM Profits

A

Answer: C

44
Q

You use Microsoft SQL Server 2012 database to develop a shopping cart application. You need torotate the unique values of the ProductName field of a table-valued expression into multiple columns inthe output.<br></br> Which Transact-SQL operator should you use?<br></br> A. CROSS JOIN<br></br> B. CROSS APPLY<br></br> C. PIVOT<br></br> D. UNPIVOT

A

Answer: C PIVOT

45
Q

You administer a Microsoft SQL Server database that supports a shopping application. You need to retrieve a list of customers who live in territories that do not have a sales person. Which Transact- SQL query or queries should you use? Choose all that apply.<br></br> A. SELECT CustomerID FROM Customer<br></br> WHERE TerritoryID <> <strong>SOME</strong>(SELECT TerritoryID FROM Salesperson)<br></br> B. SELECT CustomerID FROM Customer<br></br> WHERE TerritoryID <> <strong>ALL</strong>(SELECT TerritoryID FROM Salesperson)<br></br> C. SELECT CustomerID FROM Customer<br></br> WHERE TerritoryID <> <strong>ANY</strong>(SELECT TerritoryID FROM Salesperson)<br></br> D. SELECT CustomerID FROM Customer<br></br> WHERE TerritoryID<strong> NOT IN</strong>(SELECT TerritoryID FROM Salesperson)

A

Answer: B, D

46
Q

Your database contains a table named SalesOrders. The table includes a DATETIME column named OrderTime that stores the date and time each order is placed. There is a non-clustered index on the OrderTime column. The business team wants a report that displays the total number of orders placed on the current day. You need to write a query that will return the correct results in the most efficient manner.Which Transact-SQL query should you use?<br></br> A. SELECT COUNT() FROM SalesOrders WHERE <strong>OrderTime = CONVERT(DATE, GETDATE())</strong><br></br> B. SELECT COUNT() FROM SalesOrders WHERE <strong>OrderTime = GETDATE()</strong><br></br> C. SELECT COUNT() FROM SalesOrders WHERE <strong>CONVERT(VARCHAR, OrderTime, 112) = CONVERT(VARCHAR, GETDATE(I, 112))</strong><br></br> D. SELECT COUNT() FROM SalesOrders WHERE <strong>OrderTime >= CONVERT(DATE, GETDATE()) AND OrderTime < DATEADD(DAY, CONVERT(DATE, GETDATE()))</strong>

A

Answer: D

47
Q

Your application contains a stored procedure for each country. Each stored procedure accepts anemployee identification number through the @EmpID parameter. You plan to build a single process foreach employee that will execute the stored procedure based on the country of residence.Which approach should you use?<br></br> A. A recursive stored procedure<br></br> B. Trigger<br></br> C. An UPDATE statement that includes CASE<br></br> D. Cursor<br></br> E. The foreach SQLCLR statement

A

Answer: D Cursor

48
Q

You are developing a database application by using Microsoft SQL Server 2012. An application that uses a database begins to run slowly. You discover that during reads, the transaction experiences blocking from concurrent updates. You need to ensure that throughout the transaction the data maintains the original version. What should you do?<br></br> A. Add a HASH hint to the query.<br></br> B. Add a LOOP hint to the query.<br></br> C. Add a FORCESEEK hint to the query.<br></br> D. Add an INCLUDE clause to the index.<br></br> E. Add a FORCESCAN hint to the Attach query.<br></br> F. Add a columnstore index to cover the query.<br></br> G. Enable the optimize for ad hoc workloads option.<br></br> H. Cover the unique clustered index with a columnstore index.<br></br> I. Include a SET FORCEPLAN ON statement before you run the query.<br></br> J. Include a SET STATISTICS PROFILE ON statement before you run the query.<br></br> K. Include a SET STATISTICS SHOWPLAN_XML ON statement before you run the query.<br></br> L. Include a SET TRANSACTION ISOLATION LEVEL REPEATABLE READ statement before you run the query.<br></br> M. Include a SET TRANSACTION ISOLATION LEVEL SNAPSHOT statement before you run the query.<br></br> N. Include a SET TRANSACTION ISOLATION LEVEL SERIALIZABLE statement before you run the query.

A

Answer: M

49
Q

You are developing a database application by using Microsoft SQL Server 2012. You have a query that runs slower than expected. You need to capture execution plans that will include detailed information on missing indexes recommended by the query optimizer. What should you do?<br></br> A. Add a HASH hint to the query.<br></br> B. Add a LOOP hint to the query.<br></br> C. Add a FORCESEEK hint to the query.<br></br> D. Add an INCLUDE clause to the index.<br></br> E. Add a FORCESCAN hint to the Attach query.<br></br> F. Add a columnstore index to cover the query.<br></br> G. Enable the optimize for ad hoc workloads option.<br></br> H. Cover the unique clustered index with a columnstore index.<br></br> I. Include a SET FORCEPLAN ON statement before you run the query.<br></br> J. Include a SET STATISTICS PROFILE ON statement before you run the query.<br></br> K. Include a SET STATISTICS SHOWPLAN_XML ON statement before you run the query.<br></br> L. Include a SET TRANSACTION ISOLATION LEVEL REPEATABLE READ statement before you run the query.<br></br> M. Include a SET TRANSACTION ISOLATION LEVEL SNAPSHOT statement before you run the query.<br></br> N. Include a SET TRANSACTION ISOLATION LEVEL SERIALIZABLE statement before you run the query.

A

Answer: K

50
Q

You are developing a database application by using Microsoft SQL Server 2012. An application that uses a database begins to run slowly. You discover that a large amount of memory is consumed by single-use dynamic queries. You need to reduce <span><span>procedure cache usage</span></span> from these statements without creating any additional indexes. What should you do?<br></br> A. Add a HASH hint to the query.<br></br> B. Add a LOOP hint to the query.<br></br> C. Add a FORCESEEK hint to the query.<br></br> D. Add an INCLUDE clause to the index.<br></br> E. Add a FORCESCAN hint to the Attach query.<br></br> F. Add a columnstore index to cover the query.<br></br> G. Enable the optimize for ad hoc workloads option.<br></br> H. Cover the unique clustered index with a columnstore index.<br></br> I. Include a SET FORCEPLAN ON statement before you run the query.<br></br> J. Include a SET STATISTICS PROFILE ON statement before you run the query.<br></br> K. Include a SET STATISTICS SHOWPLAN_XML ON statement before you run the query.<br></br> L. Include a SET TRANSACTION ISOLATION LEVEL REPEATABLE READ statement before you run the query.<br></br> M. Include a SET TRANSACTION ISOLATION LEVEL SNAPSHOT statement before you run the query.<br></br> N. Include a SET TRANSACTION ISOLATION LEVEL SERIALIZABLE statement before you run the query.

A

Answer: G

Enable the optimize for ad hoc workloads option

51
Q

You are developing a database application by using Microsoft SQL Server 2012. An application that uses a database begins to run slowly. Your investigation shows the root cause is a query against a read-only table that has a clustered index. The query returns the following six columns: One column in its WHERE clause contained in a non-clustered index. Four additional colum: One COUNT (*) colum based on a grouping of the four additional columns You need to optimize th statement.<br></br> A. Add a HASH hint to the query.<br></br> B. Add a LOOP hint to the query.<br></br> C. Add a FORCESEEK hint to the query.<br></br> D. Add an INCLUDE clause to the index.<br></br> E. Add a FORCESCAN hint to the Attach query.<br></br> F. Add a columnstore index to cover the query.<br></br> G. Enable the optimize for ad hoc workloads option.<br></br> H. Cover the unique clustered index with a columnstore index.<br></br> I. Include a SET FORCEPLAN ON statement before you run the query.<br></br> J. Include a SET STATISTICS PROFILE ON statement before you run the query.<br></br> K. Include a SET STATISTICS SHOWPLAN_XML ON statement before you run the query.<br></br> L. Include a SET TRANSACTION ISOLATION LEVEL REPEATABLE READ statement before you run the query.<br></br> M. Include a SET TRANSACTION ISOLATION LEVEL SNAPSHOT statement before you run the query.<br></br> N. Include a SET TRANSACTION ISOLATION LEVEL SERIALIZABLE statement before you run the query.

A

Answer: F

Add a columnstore index to cover the query.

52
Q

You use Microsoft SQL Server 2012 to write code for a transaction that contains several statements. There is high contention between readers and writers on several tables used by your transaction. You need to minimize the use of the tempdb space. You also need to prevent reading queries from blocking writing queries. Which isolation level should you use?
A. SERIALIZABLE
B. SNAPSHOT
C. READ COMMITTED SNAPSHOT
D. REPEATABLE READ

A

Answer: C

READ COMMITTED SNAPSHOT

53
Q

You develop a database for a travel application. You need to design tables and other database objects.You create the Airline_Schedules table. You need to store the departure and arrival dates and times offlights along with time zone information.What should you do?<br></br> A. Use the CAST function.<br></br> B. Use the DATE data type.<br></br> C. Use the FORMAT function.<br></br> D. Use an appropriate collation.<br></br> E. Use a user-defined table type.<br></br> F. Use the VARBINARY data type.<br></br> G. Use the DATETIME data type.<br></br> H. Use the DATETIME2 data type.<br></br> I. Use the DATETIMEOFFSET data type.<br></br> J. Use the TODATETIMEOFFSET function.

A

Answer: I

DATETIMEOFFSET data type

54
Q

70.You develop a database for a travel application. You need to design tables and other database objects.You create a stored procedure. You need to supply the stored procedure with multiple event names andtheir dates as parameters.What should you do?<br></br> A. Use the CAST function.<br></br> B. Use the DATE data type.<br></br> C. Use the FORMAT function.<br></br> D. Use an appropriate collation.<br></br> E. Use a user-defined table type.<br></br> F. Use the VARBINARY data type.<br></br> G. Use the DATETIME data type.<br></br> H. Use the DATETIME2 data type.<br></br> I. Use the DATETIMEOFFSET data type.<br></br> J. Use the TODATETIMEOFFSET function.

A

Answer: E

Use a user-defined table type.

55
Q

71.You develop a Microsoft SQL Server 2012 database. The database is used by two web applicationsthat access a table named Products. You want to create an object that will prevent the applications fromaccessing the table directly while still providing access to the required data.You need to ensure that the following requirements are met:<br></br> - Future modifications to the table definition will not affect the applications’ ability to access data.<br></br> - The new object can accommodate data retrieval and data modification.<br></br> - You need to achieve this goal by using the minimum amount of changes to the applications.<br></br> What should you create for each application?<br></br> A. Synonyms<br></br> B. Common table expressions<br></br> C. Views<br></br> D. Temporary tables

A

Answer: C

VIEWS

56
Q

You use Microsoft SQL Server 2012 to develop a database application.<br></br> You need to create an object that meets the following requirements:<br></br> - Takes an input variable<br></br> - Returns a table of values<br></br> - Cannot be referenced within a view<br></br> Which object should you use?<br></br> A. Scalar-valued function<br></br> B. Inline function<br></br> C. User-defined data type<br></br> D. Stored procedure

A

Answer: D

Stored Procedure

57
Q

You want to add a new GUID column named BookGUID to a table named dbo.Book that alreadycontains data. BookGUID will have a constraint to ensure that it always has a value when new rows are<br></br> inserted into dbo.Book. You need to ensure that the new column is assigned a GUID for existing rows.Which four Transact-SQL statements should you use? (To answer, move the appropriate SQL statementsfrom the list of statements to the answer area and arrange them in the correct order.)Build List and Reorder:

newid()<br></br> newguid()<br></br> WITH VALUES<br></br> WITH EXISTING<br></br> CONSTRAINT CK_BookGuid CHECK<br></br> CONSTRAINT DF_BookGuid DEFAULT<br></br> ALTER TABLE dbo.Book ADD BookGuid VARCHAR(10) NOT NULL<br></br> ALTER TABLE dbo.Book ADD BookGuid UniqueIdentifier NOT NULL

A

Answer:

ALTER TABLE dbo.Book ADD BookGuid UniqueIdentifier NOT NULL<br></br> CONSTRAINT DF_BookGuid DEFAULT<br></br> newid()<br></br> WITH VALUES

58
Q

You need to create a non-clustered index on the SalesOrderID column in the OrderDetail table to includeonly rows that contain a value in the SpecialOfferID column.<br></br> Which four Transact-SQL statements should you use? (To answer, move the appropriate statements fromthe list of statements to the answer area and arrange them in the correct order.)<br></br> Build List and Reorder:

WHERE

FILTER ON

SpecialOfferID IS NOT NULL

ON dbo.OrderDetail(SalesOrderID) AS FILTERED_INDEX

ON dbo.OrderDetail(SalesOrderID)

CREATE NONCLUSTERED FILTERED INDEX fIndx_SpecialOfferId

CREATE NONCLUSTERED INDEX fIndx_SpecialOfferId

A

Answer:

CREATE NONCLUSTERED INDEX fIndx_SpecialOfferId

ON dbo.OrderDetail(SalesOrderID)

WHERESpecialOfferID IS NOT NULL

59
Q

You use Microsoft SQL Server 2012 to develop a database application. You need to implement acomputed column that references a lookup table by using an INNER JOIN against another table.What should you do?<br></br> A. Reference a user-defined function within the computed column.<br></br> B. Create a BEFORE trigger that maintains the state of the computed column.<br></br> C. Add a default constraint to the computed column that implements hard-coded values.<br></br> D. Add a default constraint to the computed column that implements hard-coded CASE statements.

A

Answer: A

Reference a user-defined function within the computed column.

60
Q

You administer a Microsoft SQL Server 2012 database named ContosoDb. The database contains a table named Suppliers and a column named IsActive in the Purchases schema. You create a new user named ContosoUser in ContosoDb. ContosoUser has no permissions to the Suppliers table. You need to ensure that ContosoUser can delete rows that are not active from Suppliers. You also need to grant ContosoUser only the minimum required permissions. Which Transact-SQL statement should you use?<br></br> A. GRANT DELETE ON Purchases.Suppliers TO ContosoUser<br></br> B. CREATE PROCEDURE Purchases.PurgeInactiveSuppliers<br></br> WITH EXECUTE AS USER = ‘dbo’<br></br> AS<br></br> DELETE FROM Purchases.Suppliers WHERE IsActive = 0<br></br> GO<br></br> GRANT EXECUTE ON Purchases.PurgelnactiveSuppliers TO ContosoUser<br></br> C. GRANT SELECT ON Purchases.Suppliers TO ContosoUser<br></br> D. CREATE PROCEDURE Purchases.PurgeInactiveSuppliers<br></br> AS<br></br> DELETE FROM Purchases.Suppliers WHERE IsActive = 0<br></br> GO<br></br> GRANT EXECUTE ON Purchases.PurgeInactiveSuppliers TO ContosoUser

A

Answer: B

<strong>CREATE PROCEDURE</strong> Purchases.PurgeInactiveSuppliers<br></br> <strong>WITH EXECUTE AS USER</strong> = ‘dbo’<br></br> AS<br></br> <strong>DELETE FROM</strong> Purchases.Suppliers WHERE IsActive = 0<br></br> GO<br></br> <strong>GRANT EXECUTE ON</strong> Purchases.PurgelnactiveSuppliers TO ContosoUser

61
Q

You use a contained database named ContosoDb within a domain. You need to create a user who canlog on to the ContosoDb database. You also need to ensure that you can port the database to differentdatabase servers within the domain without additional user account configurations.<br></br> Which type of user should you create?<br></br> A. User mapped to a certificate<br></br> B. SQL user without login<br></br> C. Domain user<br></br> D. SQL user with login

A

Answer: C

Domain User

62
Q

You administer a Microsoft SQL Server 2012 database that has multiple tables in the Sales schema.Some users must be prevented from deleting records in any of the tables in the Sales schema. You needto manage users who are prevented from deleting records in the Sales schema. You need to achieve thisgoal by using the minimum amount of administrative effort.What should you do?<br></br> A. Create a custom database role that includes the users. Deny Delete permissions on the Sales schemafor the custom database role.<br></br> B. Include the Sales schema as an owned schema for the db_denydatawriter role. Add the users to thedb_denydatawriter role.<br></br> C. Deny Delete permissions on each table in the Sales schema for each user.<br></br> D. Create a custom database role that includes the users. Deny Delete permissions on each table in theSales schema for the custom database role.

A

Answer: A

Create a custom database role that includes the users. Deny Delete permissions on the Sales schema for the custom database role.

63
Q

You administer a Microsoft SQL Server 2012 database.<br></br> The database contains a Product table created by using the following definition:

CREATE TABLE dbo.Product<br></br> (ProductID INT PRIMARY KEY,<br></br> Name VARCHAR(50) NOT NULL,<br></br> Color VARCHAR(15) NOT NULL,<br></br> Size VARCHAR(5) NOT NULL,<br></br> Style CHAR(2) NULL,<br></br> Weight DECIMAL (8,2) NULL);

<span>You need to ensure that the minimum amount of disk space is used to store the data in the Product table. What should you do?</span>

A. Convert all indexes to Column Store indexes.<br></br> B. Implement Unicode Compression.<br></br> C. Implement row-level compression.<br></br> D. Implement page-level compression

A

Answre: D

Page-level compression

64
Q

Types of Table compression

A
  • **ROW - **For row-level compression, SQL Server applies a more compact storage format to each row of a table
  • PAGE Page-level compression includes row-level plus additional compression algorithms that can be performed at the page level.
65
Q

WITH CHECK OPTION

A

When you update through the view, it restricts modifications to only rows that match the
filter condition. (the WHERE clause)

66
Q

You need to create a view that will be indexed that meets the following requirements:<br></br> - Displays the details of only students from Canada.<br></br> - Allows insertion of details of only students from Canada.<br></br> Which four Transact-SQL statements should you use? (To answer, move the appropriate SQL statements from the list of statements to the answer area and arrange them in the correct order.) Build List and Reorder:

WITH ENCRYTION<br></br> WITH CHECK OPTION<br></br> WITH SCHEMABINDING<br></br> WITH VIEW_METADATA<br></br> CREATE VIEW dbo.CanadianStudents<br></br> CREATE INDEXED VIEW dbo.CanadianStudents<br></br> AS<br></br> SELECT …FROM Student<br></br> WHERE Country = ‘Canada’

A

Answer:

CREATE VIEW dbo.CanadianStudents<br></br> WITH SCHEMABINDING<br></br> AS<br></br> SELECT …FROM Student<br></br> WHERE Country = ‘Canada’<br></br> WITH CHECK OPTION

67
Q

You administer a Microsoft SQL Server 2012 database that contains a table named OrderDetail. You discover that the NCI_OrderDetail_CustomerID non-clustered index is fragmented. You need to reduce fragmentation. You need to achieve this goal without taking the index offline. Which Transact-SQL batch should you use?

A. CREATE INDEX NCI_OrderDetail_CustomerID ON OrderDetail.CustomerID WITH DROP EXISTING<br></br> B. ALTER INDEX NCI_OrderDetail_CustomerID ON OrderDetail.CustomerID REORGANIZE<br></br> C. ALTER INDEX ALL ON OrderDetail REBUILD<br></br> D. ALTER INDEX NCI_OrderDetail_CustomerID ON OrderDetail.CustomerID REBUILD

A

Answer: B

ALTER INDEX NCI_OrderDetail_CustomerID ON OrderDetail.CustomerID REORGANIZE

68
Q

The database is used by two web applications that access a table named Products. You want to create an object that will prevent the applications from accessing the table directly while still providing access to the required data.You need to ensure that the following requirements are met:<br></br> - Future modifications to the table definition will not affect the applications’ ability to access data.<br></br> - The new object can accommodate data retrieval and data modification.<br></br> - You need to achieve this goal by using the minimum amount of changes to the existing applications.<br></br> What should you create for each application?<br></br> A. views<br></br> B. table partitions<br></br> C. table-valued functions<br></br> D. stored procedures

A

Answer: A

VIEWS

69
Q

You need to create a batch process that meets the following requirements:
- Returns a result set based on supplied parameters.
- Enables the returned result set to perform a join with a table.
Which object should you use?
A. Inline user-defined function
B. Stored procedure
C. Table-valued user-defined function
D. Scalar user-defined function

A

Answer: C

Table-valued user-defined function

70
Q

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

A

Answer: B

ENCRYPTION

71
Q

You want to create a table to store Microsoft Word documents. You need to ensure that the documents must only be accessible via Transact-SQL queries. Which Transact-SQL statement should you use?<br></br> A. CREATE TABLE DocumentStore<br></br> (<br></br> [Id] INT NOT NULL PRIMARY KEY,<br></br> [Document] VARBINARY(MAX) NULL<br></br> )<br></br> GO<br></br> B. CREATE TABLE DocumentStore<br></br> (<br></br> [Id] hierarchyid,<br></br> [Document] NVARCHAR NOT NULL<br></br> )<br></br> GO<br></br> C. CREATE TABLE DocumentStore AS FileTable<br></br> D. CREATE TABLE DocumentStore<br></br> (<br></br> [Id] [uniqueidentifier] ROWGUIDCOL NOT NULL UNIQUE,<br></br> [Document] VARBINARY(MAX) FILESTREAM NULL<br></br> )<br></br> GO

A

Answer: A

CREATE TABLE DocumentStore
(
[Id] INT NOT NULL PRIMARY KEY,
[Document] VARBINARY(MAX) NULL
)