Test Flashcards
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)
B.
ALTER TABLE Inventory ADD TotalItems
AS
ItemsInStore + ItemsInWarehouse PERSISTED
<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>
Answer: D.
CREATE TRIGGER TrgPhoneNumberChange ON Customers FOR UPDATE AS IF UPDATE<br></br> (HomeNumber) OR UPDATE (MobileNumber)<br></br> - - Create Audit Records
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.
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
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.
Answer: C
C. Convert the view into an indexed view
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)
Answer: A
ALTER TABLE Orders
ADD CONSTRAINT FX_Orders_CustomerID FOREIGN KEY (CustomerId) REFERENCES Customer (CustomerId)
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.
Answer: B
B. Create an INSTEAD OF UPDATE trigger on the view.
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.
Answer: <strong>C</strong>
<strong>C</strong>. Create an INSTEAD OF trigger on the view.
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.
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> )
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.
Answer:
CREATE TABLE Sales.OrderDetails (
ListPrice money not null,
Quantity int not null,
LineItemTotal as (ListPrice * Quantity) PERSISTED)
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.
CREATE VIEW Sales.uv_CustomerFullName
WITH SCHEMABINDING
AS
SELECT FirstName, LastName
FROM Sales.Customers
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.
Answer:
DECLARE @XML1 XML(Sales.InvoiceSchema)
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.
<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>
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.
- *Answer**:
- *CREATE PROCEDURE** usp_Customers @Count int
- *AS**
- *SELECT TOP**(@Count) Customers.LastName
- *FROM** Customers
- *ORDER BY** Customers.LastName
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
Answer:
SELECT Orders.OrderID
FROM Orders
WHERE Orders.OrderDate > CONVERT(datetime,@Parameter1)
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
Answer: **D **CROSSAPPLY
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
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), ())
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
Answer: D Numeric
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)
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)
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
Answer: B Execute As Owner
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
Answer: D
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
Answer: D.Stored Procedure
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)
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 to use .WRITE?
.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
@@ERROR
- 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
statement from the HumanResourcesJobCandidate table succeeds, the modification is retained even if
the insert into the Audit.Log table fails. A. IF @@TRANCOUNT = 0
B. IF (XACT_STATE ( ) ) = 0
C. IF (XACT_STATE ( ) ) = 1
D. IF @@TRANCOUNT = 1
an NVARCHAR(MAX) variable named @var. You need to write a Transact-SQL statement that will find
out the success of a cast to a decimal (36, 9). A. BEGIN TRY
SELECT convert(decimal(36,9), @var) AS Value, 'True' AS BadCast
END TRY
BEGIN CATCH
SELECT convert(decimal(36,9), @var) AS Value, 'False' AS BadCast
END CATCH
B. TRY(
SELECT convert(decimal(36,9), @var)
SELECT 'True' AS BadCast
)
CATCH(SELECT 'False' AS BadCast)
C. SELECT
CASE
WHEN convert(decimal(36,9), @var) IS NULL
THEN 'True'
ELSE 'False'
END
AS BadCast
D. SELECT
IIF(TRY_PARSE(@var AS decimal(36,9)) IS NULL, 'True', 'False')
AS BadCast
procedure that will update multiple tables within a transaction. You need to ensure that 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?
A. SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
B. SET XACT_ABORT OFF
C. SET TRANSACTION ISOLATION LEVEL SNAPSHOT
D. SET IMPLICIT_TRANSACTIONS ON
E. SET XACT_ABORT ON
F. SET IMPLICIT TRANSACTIONS OFF
The tables are related by a column named CustomerID.
You need to create a query that meets the following requirements:
- Returns the CustomerName for all customers and the OrderDate for any orders that they have placed.
- Results must include customers who have not placed any orders.
Which Transact-SQL query should you use?
A. SELECT CustomerName, OrderDate FROM Customers
RIGHT OUTER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
B. SELECT CustomerName, CrderDate FROM Customers
JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
C. SELECT CustomerName, OrderDate FROM Customers
CROSS JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
D. SELECT CustomerName, OrderDate FROM Customers
LEFT OUTER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
A. SET XACT_ABORT ON
B. SET ARITHABORT ON
C. TRY
D. BEGIN
E. SET ARITHABORT OFF
F. SET XACT_ABORT OFF
B. Add a clustered index on SalesOrderId in SalesOrderHeader.
C. Use a FORCESEEK hint in the query.
D. Update statistics on SalesOrderId on both tables.
A. SELECT COUNT(*) FROM Purchases
WHERE PurchaseTime = CONVERT(DATE, GETDATE())
B. SELECT COUNT(*) FROM Purchases
WHERE PurchaseTime = GETDATE()
C. SELECT COUNT(*) FROM Purchases
WHERE CONVERT(VARCHAR, PurchaseTime, 112) = CONVERT(VARCHAR, GETDATE(), 112)
D. SELECT COUNT(*) FROM Purchases
WHERE PurchaseTime >= CONVERT(DATE, GETDATE())
AND PurchaseTime < DATEADD(DAY, 1, CONVERT(DATE, GETDATE()))
B. Use the DATE data type.
C. Use the FORMAT function.
D. Use an appropriate collation.
E. Use a user-defined table type.
F. Use the VARBINARY data type.
G. Use the DATETIME data type.
H. Use the DATETIME2 data type.
I. Use the DATETIMEOFFSET data type.
J. Use the TODATETIMEOFFSET function
You create a view that displays the dates and times of the airline schedules on a report. You need to display dates and times in several international formats. What should you do? A. Use the CAST function.
B. Use the DATE data type.
C. Use the FORMAT function.
D. Use an appropriate collation.
E. Use a user-defined table type.
F. Use the VARBINARY data type.
G. Use the DATETIME data type.
H. Use the DATETIME2 data type.
I. Use the DATETIMEOFFSET data type.
J. Use the TODATETIMEOFFSET function.
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,
CustomerName varchar(255) NOT NULL);
B. CREATE TABLE Customer (SourceID int NOT NULL, CustomerID int NOT NULL PRIMARY KEY CLUSTERED, CustomerName varchar(255) NOT NULL);
C. CREATE TABLE Customer (SourceID int NOT NULL PRIMARY KEY CLUSTERED, CustomerID int NOT NULL UNIQUE, CustomerName varchar(255) NOT NULL);
D. CREATE TABLE Customer (SourceID int NOT NULL, CustomerID int NOT NULL, CustomerName varchar(255) NOT NULL, CONSTRAINT PK_Customer PRIMARY KEY CLUSTERED (SourceID,CustomerID));
(SourceID int NOT NULL,
CustomerID int NOT NULL,
CustomerName varchar(255) NOT NULL,
CONSTRAINT PK_Customer PRIMARY KEY CLUSTERED (SourceID, CustomerID));
SELECT 'Customer' as Source, CustID, CustLastName, phone FROM apt.Customer
UNION ALL
SELECT 'Agent' as Source, AgentID, AgentLastName, phone FROM apt.Agent
UNION ALL
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.
B. Drop the view. Re-create the view by using the SCHEMABINDING clause, and then create an index on the view.
C. Create an AFTER UPDATE trigger on the view.
D. Create an INSTEAD OF UPDATE trigger on the view.
COLUMNS_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
UPDATE(WholeSalePrice)
- - Create Audit Records
CREATE TABLE Inventory
(ItemID int NOT NULL PRIMARY KEY,
ItemsInStore int NOT NULL,
ItemsInWarehouse int NOT NULL)
You need to create a computed column that returns the sum total of the ItemsInStore and ItemsInWarehouse values for each row. A. ALTER TABLE Inventory
ADD TotalItems AS ItemsInStore + ItemsInWarehouse
B. ALTER TABLE Inventory
ADD ItemsInStore - ItemsInWarehouse = TotalItems
C. ALTER TABLE Inventory
ADD TotalItems = ItemsInStore + ItemsInWarehouse
D. ALTER TABLE Inventory
ADD TotalItems AS SUM(ItemsInStore, ItemslnWarehouse);
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.
What should you do?
A. Create an INSTEAD OF trigger on the view.
B. Create an AFTER trigger on the view.
C. Modify the view to use the WITH VIEW_METADATA clause.
D. Create a clustered index on the view.
OUTPUT inserted.ProductCode, deleted.Price, inserted.Price
INTO ProductsPriceLog(ProductCode, OldPrice, NewPrice)
B. UPDATE Products SET Price = Price * 1.05
OUTPUT inserted.ProductCode, inserted.Price, deleted.Price
INTO ProductsPriceLog(ProductCode, OldPrice, NewPrice)
C. UPDATE Products SET Price = Price * 1.05
OUTPUT inserted.ProductCode, deleted.Price, inserted.Price)
INTO ProductsPriceLog(ProductCode, OldPrice, NewPrice)
D. UPDATE Products SET Price = Price * 1.05
INSERT INTO ProductsPriceLog (ProductCode, CldPnce, NewPrice)
SELECT ProductCode, Price, Price * 1.05 FROM Products
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
Which Transact-SQL operator should you use?
A. CROSS JOIN
B. CROSS APPLY
C. PIVOT
D. UNPIVOT
A. SELECT CustomerID FROM Customer
WHERE TerritoryID <> SOME(SELECT TerritoryID FROM Salesperson)
B. SELECT CustomerID FROM Customer
WHERE TerritoryID <> ALL(SELECT TerritoryID FROM Salesperson)
C. SELECT CustomerID FROM Customer
WHERE TerritoryID <> ANY(SELECT TerritoryID FROM Salesperson)
D. SELECT CustomerID FROM Customer
WHERE TerritoryID NOT IN(SELECT TerritoryID FROM Salesperson)
A. SELECT COUNT(*) FROM SalesOrders WHERE OrderTime = CONVERT(DATE, GETDATE())
B. SELECT COUNT(*) FROM SalesOrders WHERE OrderTime = GETDATE()
C. SELECT COUNT(*) FROM SalesOrders WHERE CONVERT(VARCHAR, OrderTime, 112) = CONVERT(VARCHAR, GETDATE(I, 112))
D. SELECT COUNT(*) FROM SalesOrders WHERE OrderTime >= CONVERT(DATE, GETDATE()) AND OrderTime < DATEADD(DAY, CONVERT(DATE, GETDATE()))
A. A recursive stored procedure
B. Trigger
C. An UPDATE statement that includes CASE
D. Cursor
E. The foreach SQLCLR statement
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.
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.
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.
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.
A. Use the CAST function.
B. Use the DATE data type.
C. Use the FORMAT function.
D. Use an appropriate collation.
E. Use a user-defined table type.
F. Use the VARBINARY data type.
G. Use the DATETIME data type.
H. Use the DATETIME2 data type.
I. Use the DATETIMEOFFSET data type.
J. Use the TODATETIMEOFFSET function.
A. Use the CAST function.
B. Use the DATE data type.
C. Use the FORMAT function.
D. Use an appropriate collation.
E. Use a user-defined table type.
F. Use the VARBINARY data type.
G. Use the DATETIME data type.
H. Use the DATETIME2 data type.
I. Use the DATETIMEOFFSET data type.
J. Use the TODATETIMEOFFSET function.
- Future modifications to the table definition will not affect the applications' ability to access data.
- The new object can accommodate data retrieval and data modification.
- You need to achieve this goal by using the minimum amount of changes to the applications.
What should you create for each application?
A. Synonyms
B. Common table expressions
C. Views
D. Temporary tables
You need to create an object that meets the following requirements:
- Takes an input variable
- Returns a table of values
- Cannot be referenced within a view
Which object should you use?
A. Scalar-valued function
B. Inline function
C. User-defined data type
D. Stored procedure
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 statements from the list of statements to the answer area and arrange them in the correct order.) Build List and Reorder: newid()
newguid()
WITH VALUES
WITH EXISTING
CONSTRAINT CK_BookGuid CHECK
CONSTRAINT DF_BookGuid DEFAULT
ALTER TABLE dbo.Book ADD BookGuid VARCHAR(10) NOT NULL
ALTER TABLE dbo.Book ADD BookGuid UniqueIdentifier NOT NULL
CONSTRAINT DF_BookGuid DEFAULT
newid()
WITH VALUES
Which four Transact-SQL statements should you use? (To answer, move the appropriate statements from the list of statements to the answer area and arrange them in the correct order.)
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. Reference a user-defined function within the computed column.
B. Create a BEFORE trigger that maintains the state of the computed column.
C. Add a default constraint to the computed column that implements hard-coded values.
D. Add a default constraint to the computed column that implements hard-coded CASE statements.
A. GRANT DELETE ON Purchases.Suppliers TO ContosoUser
B. CREATE PROCEDURE Purchases.PurgeInactiveSuppliers
WITH EXECUTE AS USER = 'dbo'
AS
DELETE FROM Purchases.Suppliers WHERE IsActive = 0
GO
GRANT EXECUTE ON Purchases.PurgelnactiveSuppliers TO ContosoUser
C. GRANT SELECT ON Purchases.Suppliers TO ContosoUser
D. CREATE PROCEDURE Purchases.PurgeInactiveSuppliers
AS
DELETE FROM Purchases.Suppliers WHERE IsActive = 0
GO
GRANT EXECUTE ON Purchases.PurgeInactiveSuppliers TO ContosoUser
WITH EXECUTE AS USER = 'dbo'
AS
DELETE FROM Purchases.Suppliers WHERE IsActive = 0
GO
GRANT EXECUTE ON Purchases.PurgelnactiveSuppliers TO ContosoUser
Which type of user should you create?
A. User mapped to a certificate
B. SQL user without login
C. Domain user
D. SQL user with login
A. Create a custom database role that includes the users. Deny Delete permissions on the Sales schema for the custom database role.
B. Include the Sales schema as an owned schema for the db_denydatawriter role. Add the users to the db_denydatawriter role.
C. Deny Delete permissions on each table in the Sales schema for each user.
D. Create a custom database role that includes the users. Deny Delete permissions on each table in the Sales schema for the custom database role.
The database contains a Product table created by using the following definition: CREATE TABLE dbo.Product
(ProductID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Color VARCHAR(15) NOT NULL,
Size VARCHAR(5) NOT NULL,
Style CHAR(2) NULL,
Weight DECIMAL (8,2) NULL); 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? A. Convert all indexes to Column Store indexes.
B. Implement Unicode Compression.
C. Implement row-level compression.
D. Implement page-level compression
- Displays the details of only students from Canada.
- Allows insertion of details of only students from Canada.
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
WITH CHECK OPTION
WITH SCHEMABINDING
WITH VIEW_METADATA
CREATE VIEW dbo.CanadianStudents
CREATE INDEXED VIEW dbo.CanadianStudents
AS
SELECT ...FROM Student
WHERE Country = 'Canada'
WITH SCHEMABINDING
AS
SELECT ...FROM Student
WHERE Country = 'Canada'
WITH CHECK OPTION
B. ALTER INDEX NCI_OrderDetail_CustomerID ON OrderDetail.CustomerID REORGANIZE
C. ALTER INDEX ALL ON OrderDetail REBUILD
D. ALTER INDEX NCI_OrderDetail_CustomerID ON OrderDetail.CustomerID REBUILD
- Future modifications to the table definition will not affect the applications' ability to access data.
- The new object can accommodate data retrieval and data modification.
- You need to achieve this goal by using the minimum amount of changes to the existing applications.
What should you create for each application?
A. views
B. table partitions
C. table-valued functions
D. stored procedures
A. CREATE TABLE DocumentStore
(
[Id] INT NOT NULL PRIMARY KEY,
[Document] VARBINARY(MAX) NULL
)
GO
B. CREATE TABLE DocumentStore
(
[Id] hierarchyid,
[Document] NVARCHAR NOT NULL
)
GO
C. CREATE TABLE DocumentStore AS FileTable
D. CREATE TABLE DocumentStore
(
[Id] [uniqueidentifier] ROWGUIDCOL NOT NULL UNIQUE,
[Document] VARBINARY(MAX) FILESTREAM NULL
)
GO