Sie sind auf Seite 1von 3

Data Types binary,varbinary,char,varchar,datetime,smalldatetime,decimal,numeric,float,real, tinyint,smallint,int,bigint,money,smallmoney,bit,cursor,sql_variant,table,timest amp,uniqueidentifier,text,ntext,image,nchar,nvarchar Variable Declaration DECLARE <Variable_Name> <Data_Type> Comments --Single line comment /*Multi-line

comments*/ Select Statement: SELECT [ALL | DISTINCT] <Select_List> [AS <Alias>] FROM <Table_Name>,<View_Name>,<Table_Alias> [WHERE] <Criteria_Expression> [ORDER BY]<Column> [GROUP BY] <Column> [HAVING] <Search_Condition> [UNION] SELECT <Select_List> FROM <Table_Name>,<View_Name>,<Table_Alias> [WHERE] <Criteria_Expression> [ORDER BY]<Column> [GROUP BY] <Column> [HAVING] <Search_Condition> Select Clauses: DISTINCT: Specifies that only unique rows can be in the result set ORDER BY: Specify a column to sort the results by GROUP BY: Specifies the groups the results are polaced HAVING: Specifies a search condition UNION: Combines the results of 2 or more queries into single result set Update Statement: UPDATE <Table_Name> SET <Column_Name> = {<Expression> | DEFAULT | NULL} WHERE <Search_Condition> Insert Statement: INSERT INTO <Table_Name>[<Column_List>] VALUES ({DEFAULT | NULL | <Expression>} [,...n]) Delete Statement: DELETE FROM <Table_Name> [WHERE <Search_Condition>] Arithmetic Operators: +(Add),-(Subtract),*(Multiply),/(Divide),%(Modulos) Assignment Operator: =(Equals) Bitwise Operators: &(Bitwise AND),|(Bitwise OR),^(Bitwise Exclusive OR) Comparison Operators: =(Equals),>(Greater Than),<(Less Than),>=(Greater Than or Equal),<=(Less Than or Equal),<>(Not Equal)

Logical Operators: ALL: Compares a scalar value AND: Combines 2 boolean expressions (Both conditions must be true) (<Boolean_Exp ression> AND <Boolean_Expression>) ANY: Compares scalar value with single-column set of values BETWEEN: Specifies a range to test (<Expression> [NOT] BETWEEN <Begin_Expression > AND <End_Expression>) EXISTS: Specifies a subquery to test for the existance of rows (IF [NOT] EXISTS( <Sub_Query>)) IN: Determines if given value matches any in list or subquery (<Test_Expression> [NOT] IN <Sub_Query>) LIKE: Determines if character string matches a specified pattern (<Expression> [ NOT] LIKE <Pattern*> NOT: Negates a boolean value (NOT <Boolean_Expression>) OR: Combines 2 conditions (only 1 condition must be true) (<Boolean_Expression> OR <Boolean_Expression>) *Pattern: % Any string of 0 or more characters (<Expression> LIKE '%<Value>%') _(Underscore)] Any single character (<Expression> LIKE '_<Value>') [] Any character in specified range or set (<Expression> LIKE '[<Range>]<Value>' ) [^] Any character not in specified range or set (<Expression> LIKE '[^]<value>') String Concatenation Operator: + Case Statement CASE <Input_Expression> WHEN <Condition> THEN <Result_Expression> [.......] ELSE <Else_Expression> Cast: Cast a value as a specific data type CAST(<Expression> AS <Data_Type> [(<Length>)]) Convert: Convert a value to a specific data type CONVERT(<Data_Type> [(<Length>)], <Expression> [<Style>]) Stored Procedure Create <Procedure_Name>[Parameters] AS IsDate: Check if a value is a true date ISDATE(<Expression>) IsNull: Check if a value is null, and replace with replacement value ISNULL(<Check_Expression>,<Replacement_Value>) String Functions: LEFT: Return the left [n] characters of a string -> LEFT(<Character_Expression>, <Length>) RIGHT: Returns the right [n] characters of a string -> RIGHT(<Character_Expressi on>,<Length>) LEN: Return the length of a string -> LEN(<String_Expression>) REPLACE: Replace specified portion/characters in a string -> REPLACE(<Search_Str ing>,<Search_Value>,<Replacement_Value>) SUBSTRING: Returns the specified part of a string -> SUBSTRING(<Expression>,<Sta rt_Position>,<Length>) CHARINDEX: Returns starting position of specified expression -> CHARINDEX(<Speci fied_Expression>,<Search_Expression>[,<Start_Location>] LOWER: Convert all characters to lowercase -> LOWER(<Character_Expression>) UPPER: Converts all characters to uppercase -> UPPER(<Character_Expression>)

LTRIM: Removes leading spaces -> LTRIM(<Character_Expression>) RTRIM: Removes all trailing spaces -> RTRIM(<Character_Expression>) STUFF: Deletes length of characters and inserts another set -> STUFF(<Character_ Expression>,<Start>,<Length>,<Insert_Characters>) Aggregrate Functions: AVG: Returns the average of the values in a group -> AVG([ALL|DISTINCT] <Express ion>) COUNT: Returns the number of items in a group -> COUNT([ALL|DISTINCT] <Expressio n>) MAX: Returns maximum value in an expression -> MAX([ALL|DISTINCT] <Expression>) MIN: Returns the minimum value in an expression -> MIN([ALL|DISTINCT] <Expressio n>) SUM: Returns sum of all values in an expression -> SUM([ALL|DISTINCT] <Expressio n>)

Das könnte Ihnen auch gefallen