TSQL复习笔记(一)

数据类型

整数类型 int(4字节) tinyint(1字节0-255) smallint(2字节) bigint(8字节)
逻辑类型 bit 取值只能是0或者1 不是0都表示为1

浮点类型 单精度real ,双精度float --表示近似数字
            decimal 和numeric表示精确数值类型
字符类型 char[0-8000] ,varchar ,text
二进制数据类型 binary(8000字节) ,varbinary--可变 ,image ,timestamp--时间标记类型 ,uniqueidentifier--唯一识别符类型
时间数据类型 datetime ,smalldatetime
货币数据类型 money ,smallmoney

自定义数据类型 exec sp_addtype 系统存储过程

变量 

局部变量与全局变量

注释

行注释与块注释

运算符

算术运算符:+, – ,* ,/ ,%(取模)

赋值运算符:=

按位运算符:& ,| ,^

比较运算符:> ,< ,<= ,<= ,!= ,<> ,!> ,!< ,=

字符串并置运算符:+

逻辑运算符:all ,and ,any ,between ,exists ,in ,like ,not ,or ,some

一元运算符:+(正), -(负) ,~(按位not)

通配符

% , _

流程控制命令

begin …end,break,continue,goto label,if…else,return,while

waitfor [time,delay]

case

简单case函数

case搜索

批处理命令 go

切换数据库命令 use

数据控制命令

grant命令 grant…on 数据库对象 to 角色或者用户名

deny命令 deny…on 数据库对象 to 角色或用户

revoke命令 revoke from 角色或用户

调试命令 print ,raiserror

常用函数

聚合函数

avg,count(返回非空置个数),count(*)-返回全部记录个数,包含空值

max,min,sum

数学函数

abs 绝对值

ceiling 返回大于或者等于所给数字的最小整数

floor 返回小于或者等于所给数字的最大整数

power 幂次数的乘方

round 四舍五入 并指定精度

square 返回一个数的平方

sqrt 平方根

字符串函数

char 将int转化为字符 只uneng用于 0-255之间的整数

charindex 在一个字符串中查找另一个字符串中的起始位置

left,right

len

lower,upper

ltrim,rtrim

日期函数

dateadd

datediff

datepart

day

getdate

month

year

转换函数

cast(expression as datatype)

convert(newdatatype,expression)

系统函数

current_user 与user_name() 返回当前用户

datalength 返回任何表达式所占用的字节数

host_name 返回当前所登录的计算机名字

system_user 返回当前所登录的用户名称

原文地址:https://www.cnblogs.com/de0319gh/p/1802515.html