70-761 Flashcards Preview

CAE > 70-761 > Flashcards

Flashcards in 70-761 Deck (93)
Loading flashcards...
1

What are the types of rank functions?

Rank
Dense Rank
NTILE
Row Number

2

APPLY operatiors

CROSS APPLY (similar to inner join)
OUTER APPLY (similar to left outer join)

3

Stored procedure options

Encryption
Execute as: owner, self, caller, and user
Recompile

4

Why would you use recompile?

When a stored procedure is executed, its execution plan is cached. If you want the system to come up with a new execution plan, use recompile.

5

Differences between WHERE and HAVING

WHERE:
- Filters input
- Before “Group By”
- No aggregate
- Applies to individual records

HAVING:
- Filters results
- After “Group By” (required when using 'having')
- Applies to summarised group records

6

Differences between scalar and multi-valued subqueries

SCALAR SUBQUERY:
- Returns a single value
- Used with =, , <>

MULTI-VALUED SUBQUERY:
- Returns multiple values as a single column set to the outer query
- Used with IN predicate

7

Guidelines for UNION and UNION ALL

- Data types must be compatible
- Column aliases must be expressed in the first query
- Number of columns must be the same

8

Which value is returned by this select?
SELECT COALESCE(NULL, NULL, 'third_value', 'fourth_value') ...

The third value because the third value is the first value that is not null.

9

What will these select statements return?
NULLIF ('Hello', 'Hello')
NULLIF ('Hello', 'World')

NULLIF ('Hello', 'Hello') -> NULL
NULLIF ('Hello', 'World') -> Hello

10

What does OUTPUT clause do?

Returns information from, or expressions based on, each row affected by an INSERT, UPDATE, DELETE, or MERGE statement.

11

When would you use $action?

When using OUTPUT with MERGE.
The OUTPUT returns a row for every row in target_table that is updated, inserted, or deleted, in no particular order. $action can be specified in the output clause. $action is a column of type nvarchar(10) that returns one of three values for each row: 'INSERT', 'UPDATE', or 'DELETE', according to the action that was performed on that row.

12

What does RAND() Function do?

Returns a random decimal number. It returns a value between 0 (inclusive) and 1 (exclusive).
It will return a completely random number if no seed is provided, and a repeatable sequence of random numbers if a seed value is use.

13

What is the result of this statement?
SELECT SUBSTRING('SQL Tutorial', 1, 3) AS ExtractString;

ExtractString
SQL

SUBSTRING(string, start_pos, number_of_chars)

14

What does STUFF function do?

Deletes a part of a string and then inserts another part into the string, starting at a specified position.
STUFF(string1, start, length, add_string)

Example: SELECT STUFF('SQL Tutorial', 1, 3, 'HTML');
Result: HTML Tutorial

15

What does REPLACE function do?

Replaces all occurrences of a substring within a string, with a new substring. This function performs a case-sensitive replacement.
REPLACE(string1, string_to_replace, replacement_string)

Example:
SELECT REPLACE('SQL Tutorial', 'T', 'M');
Result: SQL MuMorial

16

What does RTRIM do?

Removes trailing spaces from a string.

Example:
SELECT RTRIM('SQL Tutorial ') AS RightTrimmedString;
Result:
RightTrimmedString
SQL Tutorial

17

What is columnstore?

Data that's logically organized as a table with rows and columns, and physically stored in a column-wise data format.

18

What is rowstore?

Data that's logically organized as a table with rows and columns, and physically stored in a row-wise data format. This format is the traditional way to store relational table data.

19

What does @@ROWCOUNT do?

Returns the number of rows affected by the last statement.

UPDATE HumanResources.Employee
SET JobTitle = N'Executive'
WHERE NationalIDNumber = 123456789
IF @@ROWCOUNT = 0
PRINT 'Warning: No rows were updated';

20

What does @@IDENTITY do?

Returns the last-inserted identity value.

21

What are the differences between IDENT_CURRENT, SCOPE_IDENTITY, and @@IDENTITY?

All these functions return values that are inserted into identity columns.

IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. Returns the value generated for a specific table in any session and any scope. IDENT_CURRENT ('TableName').

SCOPE_IDENTITY and @@IDENTITY return the last identity values that are generated in any table in the current session. However, SCOPE_IDENTITY returns values inserted only within the current scope;

@@IDENTITY is not limited to a specific scope. The last identity generated in the session.

22

Steps to use a cursor

- Declare cursor
- Open cursor
- Fetch cursor
- Create loop
- Use data
- Close cursor

Note: cursors involve row based logic. It generally slows performance.

23

What is heap?

A table without a clustered index. One or more nonclustered indexes can be created on tables stored as a heap. Data is stored in the heap without specifying an order

24

What is the difference between clustered and non-clustered indexes?

A clustered index actually describes the order in which records are physically stored on the disk, hence the reason you can only have one.
A Non-Clustered Index defines a logical order that does not match the physical order on disk. You can have several non-clustered indexes, but using them in excess might also cause overhead as they require more space.

25

How to check a table's index?

Execute sp_helpindex Table_Name

26

What does datetimeoffset do?

Defines a date that is combined with a time of a day that has time zone awareness and is based on a 24-hour clock.

27

Triggers

INSTEAD OF triggers fire in place of the triggering action and before constraints are processed
If the constraints are violated, the AFTER trigger is not executed.
If there are AFTER triggers on the table, they will fire after constraint processing.

28

What is a computed column?

A virtual column that is not physically stored in the table, unless the column is marked PERSISTED.
PERSISTED specifies that the SQL Server Database Engine will physically store the computed values in the table, and update the values when any other columns on which the computed column depends are updated.

29

Example of view

—create a view named uv_CustomerFullName—
—view must be created in the Sales schema—
CREATE VIEW Sales.uv_CustomerFullName
—view must prevent the underlying structure of the customer table from being changed
WITH SCHEMABINDING
AS
—Columns must only be referenced by using one-part names—
—view must return the first name and the last name—
SELECT FirstName, LastName
—view must be able to resolve all referenced objects—
FROM Sales.Customers

30

Using hint to optimize transaction logging and locking for the statement below:
INSERT INTO OrdersHistorical
SELECT * FROM CompletedOrders

‘a’ – holdlock is wrong because it lock whole table until operation is done {transaction is commited};
‘b’ – rowlock – you use it to update/delete some rows {not many}, for only insert & select its useless and it has bad performance;
‘c’ – xlock – as far as I know its exclusive lock – also locks everyting;
‘d’ – updlock – you use it to insert new, update or delete statements;
‘e’ – correct {for me 99%}. You should use ‘tablock’ hint to improve performance while insert/select statements. It is share lock.