Section 1

Preview this deck

SCOPE_IDENTITY

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (115)

Section 1

(50 cards)

SCOPE_IDENTITY

Front

will return the IDENTITY value inserted into an identity column within the scope of the stored procedure and will prevent the wrong value from being written to the

Back

> (Greater Than)

Front

Greater than

Back

Between .. and returns

Front

row version for a specified period

Back

quarter

Front

qq, q

Back

Identity (1,1)

Front

IDENTITY [ (seed , increment) ]

Back

LEFT JOIN

Front

This would return the last three sales regardless of the employee found in the Employee table. The three last sales would be calculated first and then matched to information from the Employee table.

Back

EOMONTH ( start_date [, month_to_add ] )

Front

--returns end of month date as data_type DATE

Back

SELECT - FOR Clause

Front

1.Allow updates while viewing query results in a browse mode cursor by specifying FOR BROWSE. 2.Format query results as XML by specifying FOR XML. 3.Format query results as JSON by specifying FOR JSON.

Back

= (Equals)

Front

Equal to

Back

To be SARGable, a predicate must, on one side

Front

have a column, not an expression on a column. So, <column> <operator> <expression>

Back

week

Front

wk, ww

Back

month

Front

mm, m

Back

DATEFROMPARTS()

Front

Year,Month,day

Back

weekday

Front

dw, w

Back

day

Front

dd, d

Back

millisecond

Front

ms

Back

Contained in returns

Front

only rows in a specified period

Back

!< (Not Less Than)

Front

Not less than (not ISO standard)

Back

< (Less Than)

Front

Less than

Back

minute

Front

mi, n

Back

A function cannot be used to

Front

insert a row into a table

Back

from .... to

Front

returns row versions for a specified version

Back

THROW

Front

re-raises the same error that caused control to be given to the CATCH block. You should not use the RAISERROR(1205, 'Deadlock', 16, 1); statement. RAISERROR cannot be used to raise system errors. System errors have error numbers less than 50000.

Back

INNER JOIN

Front

This would return the last three sales, regardless of the employee found in the Employee table. The three last sales would be calculated first and then matched to information from the Employee table.

Back

!< or >=

Front

values that are not less than the limit

Back

nanosecond

Front

ns

Back

IDENT_CURRENT

Front

returns the last value generated for an IDENTITY column for a specified table or view.

Back

cross join

Front

This would return the last three sales regardless of the employee found in the Employee table. These three rows would be then attached to every employee from the Employee table, which produces incorrect results.

Back

as of

Front

returns the state before forecasts were added

Back

second

Front

ss, s

Back

<> (Not Equal To)

Front

Not equal to

Back

a view returns

Front

a result set and cannot be used to insert a row into a table

Back

@@IDENTITY

Front

We should use which function to get the number of rows affected by the last statement; This always returns the last identity value inserted into an identity column anywhere in the system. This could therefore write to the wrong identity value to the SalesInvoiceLine table if an IDENTITY value has been created elsewhere in the system.

Back

Select Statement

Front

[ WITH { [ XMLNAMESPACES ,] [ <common_table_expression> ] } ] SELECT select_list [ INTO new_table ] [ FROM table_source ] [ WHERE search_condition ] [ GROUP BY group_by_expression ] [ HAVING search_condition ] [ ORDER BY order_expression [ ASC | DESC ] ] The UNION, EXCEPT, and INTERSECT operators can be used between queries to combine or compare their results into one result set.

Back

RAISERROR();

Front

always requires parameters and cannot be used to raise system errors.

Back

RAISERROR(1205, 'Deadlock', 16, 1)

Front

RAISERROR(1205, 'Deadlock', 16, 1); statement. RAISERROR cannot be used to raise system errors. System errors have error numbers less than 50000.

Back

Dateadd syntax

Front

DATEADD (datepart , number , date )

Back

!= (Not Equal To)

Front

Not equal to (not ISO standard)

Back

hour

Front

hh

Back

year

Front

yy, yyyy

Back

<= (Less Than or Equal To)

Front

Less than or equal to

Back

>= (Greater Than or Equal To)

Front

Greater than or equal to

Back

datetime data type

Front

Although @dt is declared with the datetime data type, SQL Server will implicitly convert the date into a datetime2 data type. Datetime must be in increments of 0.000, 0.003, or 0.007 for the value to be correctly compared. Otherwise, it will be rounded. In this case, the millisecond value ends in 0, and so the correct results are returned.

Back

dayofyear

Front

dy, y

Back

cross apply

Front

This part of the query will calculate the top three latest sales for every employee. The data from the Employee table acts as a driver for the calculation that is performed in the CROSS APPLY statement.

Back

!> (Not Greater Than)

Front

Not greater than (not ISO standard)

Back

microsecond

Front

mcs

Back

sequence syntax

Front

CREATE SEQUENCE [schema_name . ] sequence_name [ AS [ built_in_integer_type | user-defined_integer_type ] ] [ START WITH <constant> ] [ INCREMENT BY <constant> ] [ { MINVALUE [ <constant> ] } | { NO MINVALUE } ] [ { MAXVALUE [ <constant> ] } | { NO MAXVALUE } ] [ CYCLE | { NO CYCLE } ] [ { CACHE [ <constant> ] } | { NO CACHE } ] [ ; ]

Back

EOMONTH

Front

The function of _____ returns the serial number of the last day of the month before or after a specified number of months.

Back

The other requirement for a predicate to be SARGable, for SQL Server at least, is that the column and expression are

Front

of the same data type or, if the data types differ, such that the expression will be implicitly converted to the data type of the column.

Back

Section 2

(50 cards)

Original_Login()

Front

returns the underlying Windows identity regardless of the security context or impersonation level that is being used

Back

Truncate table is the

Front

fastest way of removing all from a table

Back

Where CustomerID = SOME

Front

SOME compares a value to a set of values in the subquery and returns TRUE when any one row matches.

Back

Cross Apply

Front

used to invoke a table-valued function and return only rows from the function that match to rows in the StateProvince table. States that do not have any cities with sales are not included.

Back

CTE Scope

Front

the scope of a single statement such as SELECT, INSERT, UPDATE, or DELETE and so could not be used several times within a batch.

Back

Truncate table cannot be used with a

Front

where clause

Back

Set xact_abort on changes

Front

statement-terminating errors to batch-terminating errors but has no impact here because divide by zero is already a statement-terminating error

Back

Procedures

Front

Accept input parameters and return multiple values in the form of output parameters to the calling program. Contain programming statements that perform operations in the database. These include calling other procedures. Return a status value to a calling program to indicate success or failure (and the reason for failure).

Back

When you are using a table-valued functin, should you use Cross Join or Cross Apply

Front

Cross apply

Back

Table Variables Scope

Front

The contents of a table variable will persist within a batch

Back

Json_query

Front

allows for lists

Back

When you are in an international system, what should you use for characters?

Front

nvarchar()

Back

WITH Schemabinding is required for

Front

indexed views. prevents underlying tables from being modified in any way that would affect the view defintion

Back

RAW

Front

generates a single <row> element per row in the rowset that is returned by the SELECT statement. You can generate XML hierarchy by writing nested FOR XML queries.

Back

Provide Json path when

Front

When you call OPENJSON to create a relational view of JSON data. For more info, see OPENJSON (Transact-SQL). When you call JSON_VALUE to extract a value from JSON text. For more info, see JSON_VALUE (Transact-SQL). When you call JSON_QUERY to extract a JSON object or an array. For more info, see JSON_QUERY (Transact-SQL). When you call JSON_MODIFY to update the value of a property in a JSON string. For more info, see JSON_MODIFY (Transact-SQL).

Back

When to use a unique constraint instead of a primary key constraint

Front

1. you want to enforce the uniqueness of a column, or combination of columns, that is not the primary key. 2. as with any value participating in a UNIQUE constraint, only one null value is allowed per column.

Back

table-valued functions

Front

1. pass a parameter to a table-valued function 2. use a table-valued function in a view 3. cannot return multiple result sets from a table valued function 4. can use results from a table-valued function in a SELECT statement

Back

SQL-92 syntax

Front

1. produces code that is easier to understand (separates join conditions from where clause) 2. current bes tpractice 3. does not produce more efficient query plans 4. requires more typing 5. less error prone

Back

DECLARE @json NVARCHAR(MAX) SET @json=N'{ "info":{ "type":1, "address":{ "town":"Bristol", "county":"Avon", "country":"England" }, "tags":["Sport", "Water polo"] }, "type":"Basic" }' SELECT * FROM OPENJSON(@json,N'lax $.info')

Front

Results Key Value Type type 1 0 address { "town":"Bristol", "county":"Avon", "country":"England" } 5 tags [ "Sport", "Water polo" ] 4

Back

table-valued function

Front

Selects data and returns the results as a table. Cannot modify any permanent tables.

Back

int

Front

approximately 2 billion customerIDs and is stored in 4 bytes

Back

CTE can only be used

Front

within the current statement and so cannot be used in different places

Back

Predicates with LIKE are only SARGable if

Front

the wildcard is not at the start of the string.

Back

user-defined inline function

Front

returns a table data type and will give the best performance

Back

= operator

Front

Requires one value

Back

stored procedures

Front

1. Reduced server/client network traffic 2. stronger security (do not have direct permissions on those underlying objects; Execute as) 3. can be encrypted (not the underlining data) 4. Easier maintenance 5. improved performance

Back

TRY_Parse('2012-31-07 11:33:00' as date USING 'en-us') what would the expression evaluate to?

Front

The expression evaluates to NULL as a date. The date expression provided is invalid for en-us culture (USA). The result of TRY_PARSE for invalid dates is a NULL. The data type will match the requested type of date.

Back

geography type holds

Front

latitude, longitude

Back

Identity function takes in

Front

property of the column, takes seed, and increment as its arguments

Back

ISNULL function

Front

A function that tests a field value or an expression for a null value; if the field value or expression is null, the result is true; otherwise, the result is false; only limited to two parameters

Back

tinyint

Front

0 to 255

Back

cannot use truncate table if a

Front

column in the table is referenced by a foreign key constraint and so you should use DELETE to remove records

Back

derived table can only be used

Front

within the current statement and so cannot be used in different places

Back

Path mode

Front

1. In lax mode, the function returns empty values if the path expression contains an error. 2. In strict mode, the function raises an error if the path expression contains an error.

Back

stored procedure scope

Front

cannot be invoked from within a SELECT statement.

Back

In a FOR XML clause, you specify one of these modes:

Front

RAW AUTO EXPLICIT PATH

Back

The property path

Front

a set of path steps. Path steps can contain the following elements and operators. Key names. For example, $.name and $."first name". If the key name starts with a dollar sign or contains special characters such as spaces, surround it with quotes. Array elements. For example, $.product[3]. Arrays are zero-based. The dot operator (.) indicates a member of an object. For example, in $.people[1].surname, surname is a child of people.

Back

A table-valued user-defined function can be used

Front

anywhere a table or view could be used

Back

Cast(createddate as date) is sargable: True or False

Front

True

Back

Concat Syntax

Front

CONCAT ( string_value1, string_value2 [, string_valueN ] )

Back

Insert Sales.ProductPrices (productID, UnitPrice) Values (1,25.30), (2,33.25) Does this solution meet the goal? Why?

Front

* ProductPriceID is an IDENTITY column and will be automatically calculated. * ProductID has a foreign key reference, the value is supplied, and the ProductID values in the Sales.Product table already exist. * EffectiveDateTime is defined as NOT NULL, but the default value derived from SYSDATETIME() will be used. * UnitPrice is defined as NOT NULL but is supplied. * PricingComment is defined as NOT NULL and will be left NULL because it was not supplied. The query is a multi-row INSERT. Two rows will be inserted.

Back

bigint

Front

takes 8 bytes to store

Back

A divide by zero error and set xact_abort on

Front

Back

How to check if a function is deterministic

Front

Select OBJECT_PROPERTY (OBJECT_ID('dbo.FullName'),'IsDeterministic')

Back

Insert Sales.ProductPrices (ProductPriceID, EffectiveDateTime, UnitPrice, PricingComment) Values (3,'20170901',4.54,'Old pricing applied'); Does this solution meet the goal? Why?

Front

The insert will not succeed because an attempt is being made to insert a value for the identity column ProductPriceID when Identity_insert is not enabled

Back

Derived Table Scope

Front

You should not use a derived table. The scope of a derived table is local to the statement and so could not be used several times in the batch.

Back

Set identity insert has been turned on requires what also?

Front

a column list must be supplied in the INSERT statement

Back

IIF function

Front

evaluates a condition and returns one value if the condition is true and another value if the condition is false

Back

The AUTO mode

Front

generates nesting in the resulting XML by using heuristics based on the way the SELECT statement is specified. You have minimal control over the shape of the XML generated. The nested FOR XML queries can be written to generate XML hierarchy beyond the XML shape that is generated by AUTO mode heuristics.

Back

IFF( , ' ', ' ')

Front

Returns text

Back

Section 3

(15 cards)

datetime holds the time range to the nearest

Front

0.000,0.003, or 0.007 millisecond

Back

Pivot

Front

converts rows to columns

Back

Throw syntax

Front

THROW [ { error_number | @local_variable }, { message | @local_variable }, { state | @local_variable } ] [ ; ]

Back

smalldatetime returns

Front

zero seconds without fractions of a second

Back

Raiseerror syntax

Front

RAISERROR ( { msg_id | msg_str | @local_variable } { ,severity ,state } [ ,argument [ ,...n ] ] ) [ WITH option [ ,...n ] ]

Back

With schemabinding is written after the

Front

returns statement

Back

Unpivot

Front

converting columns to rows

Back

Indexed views improve the performance of the following types of queries:

Front

Join and aggregation operations that are frequently performed by many queries. For example, in an online-transaction-processing (OLTP) database that is recording inventories, many queries would be expected to join the ProductMaster, ProductVendor, and VendorMaster tables. Although each query that performs this join may not process many rows, the overall join processing of hundreds of thousands of such queries can be significant. Because these relationships are not likely to be updated frequently, the overall performance of the whole system could be improved by defining an indexed view that stores the joined results. Decision support workloads. Analysis systems are characterized by storing summarized, aggregated data that is infrequently updated. Additionally aggregating the data and joining many rows characterizes many decision support queries. Also, decision support systems sometimes contain wide tables with many columns or columns that are large, or both. Queries that reference a narrow subset of these columns can benefit from an indexed view that includes only the columns in the query, or a narrow superset of those columns. Creating narrow indexed views that contain a subset of the columns of a single table is known as a vertical partitioning strategy because it splits tables vertically. For example, consider the following table and indexed view:

Back

With encyrption stops the

Front

view from being published as part of SQL Server replication and is not required for an indexed view

Back

Throw should be used when

Front

you have created new code

Back

datetime2(3)

Front

to the nearest millisecond

Back

A try -- catch construction must be contained within

Front

a single batch. cannot span more than one Begin ... END block

Back

Throw transfers processing to

Front

the Catch block

Back

with check option

Front

prevents data from being amended in anyway that prevents the row from being returned by the view definition; goes after the WHERE clause, and not immediately after the Create View

Back

All of the string built-in functions are

Front

deterministic

Back