• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/30

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

30 Cards in this Set

  • Front
  • Back

What is the use of MERGE statement?

With the MERGE statement, you can MERGE data from a source table or table expression into a target table.




MERGE INTO AS TGT


USING table/ expression/select query AS SRC


ON


WHEN MATCHED [AND ]


THEN


WHEN NOT MATCHED [BY TARGET] [AND PREDICATE]


THEN INSERT...


WHEN NOT MATCHED BY SOURCE [AND PREDICATE] THEN ;.>




MERGE clause solves the issue of non deterministic update found with the JOIN clause.

Numeric vs Decimal?

Both are functionally similar. Both are declared as DECIMAL(m,d) and NUMERIC(m,d).


where m is the total number of digits and d is the number of digit after the decimal.




In both cases, m defaults to 18 and d to 0.

What is the problem with REAL and FLOAT?



REAL and FLOAT should be used in areas like scientific calculations for very large/small numbers but shouldn't be used in those cases where precision is needed. In other words, numeric/decimal data types should be used in the latter case.

CAST , CONVERT and PARSE?

SELECT CAST(1 as varchar);




SELECT CONVERT(DATE, '1/1/2012', 101);




SELECT PARSE('1/1/2012' AS DATE USING 'en-US');

CONCAT() vs string concatenation( + operator)

The +opeartor returns null on NULL input whereas CONCAT() replaces NULL input with an empty string.

FORMAT()

Returns a value formatted with the specified format and optional culture in SQL Server 2016. Use the FORMAT function for locale-aware formatting of date/time and number values as strings. For general data type conversions, use CAST or CONVERT.




DECLARE @d DATETIME = '10/01/2011';


SELECT FORMAT ( @d, 'd', 'en-gb' ) AS 'Great Britain English Result' ;


//returns 01/10/2011




FORMAT(Now(),'YYYY-MM-DD')

NULLIF()

NULLIF(col1, col2) returns null if and b are equal otherwise returns a NULL.

IIF()

IIF(, , . it's similar to COALESCE or CASE expressions.

CHOOSE()

CHOOSE(, , , ) returns the expression at the specified the position.


CHOOSE(2, 'x','y','z') returns 'y'.

ISNULL ()

ISNULL ( check_expression , replacement_value ) - Replaces NULL with the specified replacement value.


Similar to COALESCE function, but the COALESCE () is the standard.

SUBSTRING

SUBSTRING ( expression ,start , length ). numbering is 1 based. Returns part of a character, binary, text, or image expression in SQL Server.

STUFF()

STUFF ( character_expression , start , length , replaceWith_expression ). The STUFF function inserts a string into another string at the specified position by start and length values.

LEFT()

LEFT ( character_expression , integer_expression ) - Returns the left part of a character string with the specified number of characters.

REPLACE()

REPLACE ( string_expression , string_pattern , string_replacement )

REPLICATE

REPLICATE ( string_expression ,integer_expression )

CHARINDEX ()

Searches an expression for another expression and returns its starting position if found.


CHARINDEX ( expressionToFind , expressionToSearch [ , start_location ] )

PATINDEX



PATINDEX ( '%pattern%' , expression )

ROUND

ROUND ( numeric_expression , length [ ,function ] ) . Returns a numeric value, rounded to the specified length or precision.




When length is a positive number, numeric_expression is rounded to the number of decimal positions specified by length. When length is a negative number, numeric_expression is rounded on the left side of the decimal point, as specified by length.

RAND

Returns a pseudo-random float value from 0 through 1, exclusive.


RAND ( [ seed ] )

ABS

ABS ( numeric_expression ). ABS returns the absolute (positive) value of the specified numeric expression.

SIGN

SIGN ( numeric_expression ) . Returns the positive (+1), zero (0), or negative (-1) sign of the specified expression.

DATEADD()

DATEADD (datepart , number , date )

DATEDIFF()

DATEDIFF ( datepart , startdate , enddate )

DATEFROMPARTS ()

DATEFROMPARTS ( year, month, day ) - Returns a date value for the specified year, month, and day.




SELECT DATEFROMPARTS ( 2010, 12, 31 ) --returns 2010-12-31

EOMONTH ()

EOMONTH ( start_date [, month_to_add ] ). Returns the last day of the month that contains the specified date, with an optional offset.

WHERE EXISTS ( subquery ) ,


WHERE IN[/NOT IN(subquery),


WHERE (subquery) OR

Returns true if subquery returns any rows. If the subquery doesn't contain any row, it's considered as false. it's different from IN operator which returns Unknown when the result of subquery is NULL(hence producing unexpected results).




OR can also be used in place of IN but it's bit slower and verbose.

ANY, SOME or ALL operators.

SOME is an ISO standard equivalent for ANY.


=ANY operator is equivalent to IN


but <>ANY is not same as NOT IN, but <>ALL is the same as NOT IN .

spatial data in sql server?

GEOMETRY is for planar spatial data (that is, data on a flat surface).


GEOGRAPHY is for terrestrial spatial data (that is, data on the (curved) surface of the Earth)

Window analytic functions : CUME_DIST , Percentile ranking functions ?

PERCENT_RANK and CUME_DIST. Calculates the relative rank of a row within a group of rows .Use PERCENT_RANK to evaluate the relative standing of a value within a query result set or partition. PERCENT_RANK is similar to the CUME_DIST function.




PERCENT_RANK( ) OVER ( [ partition_by_clause ] order_by_clause )

Sql server 2008 vs 2012

SQL Server 2008: The Maximum number concurrent connections to SQL Server 2008 is 32767, while it is unlimited in sql server 2012.




TRY_CONVERT() and FORMAT() functions are not available in SQL Server 2008 ORDER BY Clause does not have OFFSET / FETCH options as in SQL Server 2012 .




Sequence is not available in SQL Server 2008.




The SQL Server 2008 uses 27 bit precision for spatial calculations. The SQL Server 2012 uses 48 bit precision for spatial calculations.