SQL Server Cheat Sheet

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Data Types Date Functions Create a Stored Procedure

Exact Numerics DATEADD (datepart, number, date) CREATE PROCEDURE name


bit decimal DATEDIFF (datepart, start, end) @variable AS datatype = value
tinyint money DATENAME (datepart, date) AS
smallint bit DATEPART (datepart, date) -- Comments
int numeric DAY (date) SELECT * FROM table
bigint GETDATE () GO
int GETUTCDATE ()
Approximate Numerics MONTH (date) Create a Trigger
float real YEAR (date)
Date and Time CREATE TRIGGER name
smalldatetime timestamp Dateparts ON
datetime table
Strings Year yy, yyyy FOR
char text Quarter qq, q DELETE, INSERT, UPDATE
varchar Month mm, m AS
Unicode Strings Day of Year dy, y -- Comments
nchav ntext Day dd, d SELECT * FROM table
nvarchar Week wk, ww GO
Binary Strings Hour hh
binary image Minute mi, n Create a View
varbinary Second ss, s
Miscellaneous Millisecond ms CREATE VIEW name
cursor table AS
sql_variant xml Mathematical Functions -- Comments
SELECT * FROM table
ABS LOG10 GO
Type Conversion
ACOS PI
ASIN POWER
CAST (expression AS datatype) Create an Index
ATAN RADIANS
CONVERT (datatype, expression)
ATN2 RAND CREATE UNIQUE INDEX name
CEILING ROUND ON
Ranking Functions COS SIGN table (columns)
COT SIN
RANK NTILE DEGREES SQUARE Create a Function
DENSE_RANK ROW_NUMBER EXP SQRT
FLOOR TAN CREATE FUNCTION name
Grouping (Aggregate) Functions LOG (@variable datatype(length))
RETURNS
AVG MAX String Functions datatype(length)
BINARY_CHECKSUM MIN
AS
CHECKSUM SUM ASCII REPLICATE
BEGIN
CHECKSUM_AVG STDEV CHAR REVERSE
DECLARE @return datatype(length)
COUNT STDEVP CHARINDEX RIGHT
SELECT @return = CASE @variable
COUNT_BIG VAR DIFFERENCE RTRIM
WHEN 'a' THEN 'return a'
GROUPING VARP LEFT SOUNDEX
WHEN 'b' THEN 'return b'
LEN SPACE
ELSE 'return c'
Table Functions LOWER STR
RETURN @return
LTRIM STUFF
END
ALTER DROP NCHAR SUBSTRING
CREATE TRUNCATE PATINDEX UNICODE
Available free from
REPLACE UPPER
www.ILoveJackDaniels.com
QUOTENAME

You might also like