SQL Server Cheat Sheet

SQL Server Cheat Sheet

Dateparts

Year

Quarter

yy, yyyy

qq, q

System Data Types

bigint

binary

Month

Day of Year

Day

mm, m

dy, y

dd, d

bit

char

cursor

Week

Hour

wk, ww

hh

datetime

decimal

Minute

Second

mi, n

ss, s

float

image

Millisecond

ms

int

Day Of Week dw

Date Functions

DATEADD (datepart, number, date)

DATEDIFF (datepart, start, end)

DATENAME (datepart, date)

money

nchar

ntext

numeric

nvarchar

DATEPART (datepart, date)

real

DAY (date)

GETDATE ()

smalldatetime

smallint

GETUTCDATE ()

MONTH (date)

YEAR (date)

smallmoney

sql_variant

table

text

timestamp

Convert Date Style Codes

mon dd yyyy hh:miAM

100 (or PM)

101 mm\dd\yyyy

103 dd/mm/yy

120 yyyy-mm-dd hh:mi:ss

Convert(Datatype, Date, Style)

tinyint

varbinary

varchar

uniqueidentifier

xml

Date

Time

DateTime2

DateTimeOffset

Geometry

Geography

HierarchyId

-2^63 to 2^63-1

January 1, 1753, through

December 31, 9999

- 10^38 +1 through 10^38 - 1

8 Bytes

2 4 byte

integers

- 1.79E+308 to -2.23E-308, 0

and 2.23E-308 to 1.79E+308

-2^31 (-2,147,483,648) to 2^31-1

(2,147,483,647)

4 Bytes

-922,337,203,685,477.5808

to 922,337,203,685,477.5807 8 Bytes

Equiv. to decimal

- 3.40E + 38 to -1.18E - 38, 0

and 1.18E - 38 to 3.40E + 38

4 Bytes

(Equiv. to Float(24)

January 1, 1900, through June 2 2 byte

integers

6, 2079

-2^15 (-32,768) to 2^15-1 (32,767) 2 Bytes

- 214,748.3648 to

214,748.3647

4 Bytes

0 to 255

Mathematical

Functions

ABS

ACOS

String Functions

ASCII

CHAR

ASIN

ATAN

ATN2

CHARINDEX

DIFFERENCE

LEFT

CEILING

COS

LEN

LOWER

Aggregate Functions

AVG

COT

DEGREES

LTRIM

NCHAR

BINARY_CHECKSUM

CHECKSUM

EXP

PATINDEX

FLOOR

LOG

LOG10

PI

POWER

REPLACE

QUOTENAME

REPLICATE

REVERSE

RIGHT

RADIANS

RTRIM

SUM

RAND

ROUND

SOUNDEX

SPACE

STDEV

STDDEVP

SIGN

SIN

SQUARE

SQRT

TAN

STR

STUFF

SUBSTRING

UNICODE

UPPER

VAR

VARP

Ranking Functions

RANK

DENSE_RANK

Char. to find, String to

search, [start])

(Pattern, Expression)

(String, Substring,

Replacement)

NTILE

ROW_NUMBER

CHECKSUM_AVG

COUNT

COUNT_BIG

GROUPING

MAX

MIN

(String, Start, Length)

1 Byte

Syntax

row_number() over(order by [Column])

declare CursorName cursor local fast_forward

for

{Select}

Accurate to 100 nanoseconds 1/1/1 to 12/31/9999

open CursorName

fetch next from Diff_Cursor into @ColumnA, @ColumnB

while @@FETCH_STATUS = 0

begin

{Work}

fetch next from Diff_Cursor into @ColumnA, @ColumnB

end

close CursorName

deallocate CursorName

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download