You generate a daily report according to the following query:
The Sales.ufn.GetLastOrderDate user-defined function (UDF) is defined as follows:
You need to improve the performance of the query.
What should you do?
We use a Common Table Expression (TBE) to optimize the query with a predicate pushdown.
Predicate pushdown is an optimization that applies conditions (predicates) as early as possible --- ideally preventing any loading of unneeded rows.
References:
https://modern-sql.com/feature/with/performance
You administer a Microsoft SQL Server database that contains a table named Products.
In a bit column named Discontinued, a value of 1 indicates a product is inactive, and a value of 0 indicates the product is active.
You need to create a view that returns a column with a full product status description.
Which expression should you use to define the column?
The CASE statement evaluates a list of conditions and returns one of multiple possible result expressions.
The CASE expression has two formats:
The simple CASE expression compares an expression to a set of simple expressions to determine the result.
The searched CASE expression evaluates a set of Boolean expressions to determine the result.
Both formats support an optional ELSE argument.
CASE can be used in any statement or clause that allows a valid expression.
You develop a Microsoft SQL Server database. The database contains a table defined by the following
Transact-SQL statement:
All regions have more than one employee.
You need to write a query to find the employee with the highest SalesYTD in each region with the following result set:
* First Name
* Last Name
* Region
* Sales YTD
Which Transact-SQL query should you run?
Use TOP 1 and RANK() OVER (PARTITION BY).
You are working with a table that has an XML column that contains information about books. Each book may have an associated price.
You need to write a query that returns each author on a separate row in XML format.
Which XML method should you use?
The nodes() method is useful when you want to shred an xml data type instance into relational data. It allows you to identify nodes that will be mapped into a new row.
The result of the nodes() method is a rowset that contains logical copies of the original XML instances. In these logical copies, the context node of every row instance is set to one of the nodes identified with the query expression, so that subsequent queries can navigate relative to these context nodes.
Incorrect Answers:
A: The Value() method performs an XQuery against the XML and returns a value of SQL type. This method returns a scalar value.
C: The Query() method specifies an XQuery against an instance of the xml data type. The result is of xml type. The method returns an instance of untyped XML.
D: The Exists() method returns a bit that represents one of the following conditions:
1, representing True, if the XQuery expression in a query returns a nonempty result. That is, it returns at least one XML node.
0, representing False, if it returns an empty result.
NULL if the xml data type instance against which the query was executed contains NULL.
You administer a Microsoft SQL Server instance that will support several databases.
You need to ensure that every new database created has a data type named postalcode that contains the
same attributes.
What should you do?
One option is to create SQL Server user defined data types.
One trick with new databases is to create the objects in the model database, so as new databases are created the user defined data types will automatically be available.
Currently there are no comments in this discussion, be the first to comment!