T-SQL语句分类:
数据定义语句(例:create table table_name /drop table table_name)
数据控制语句(例:grant revoke)
数据操作语句(例:select update delete)
流程控制语句(例: if else )
变量申明语句(例:declare @a int);
1、变量与常量:
常量:
数字常量:整数、小数、浮点数(12,12.1,12e10)
字符串常量:'FEFWEF'
日期常量:current_date、current_time、current_timestamp
变量:局部变量和全局变量
局部变量:(declare @a int set @a=1)
用 declare 申明,用select或者set赋值
全局变量:(@@IDENTITY......)
以@@为前缀,每个全局变量都带有不同的意义;
2、流程控制语句
顺序流程语句:begin ... end
判断流程语句:if....else 、case when then else end
( select * ,name=case
when grade>90 then '成绩优秀'
when grade>60 and grade<90 then '成绩良好'
else '成绩不及格'
end
from table_name
)
循环程序语句:while...continute...break
( declare @a int
set @a=10
while @a<1
begin
if @a%2=0
continute
else if @a%3=0
break
else
set @a=@a-1
end
)
其他一些关键字:return goto waitfor delay /time
TSQL实例(一)
猜你喜欢
转载自blog.csdn.net/a3060858469/article/details/80856539
今日推荐
周排行