TSQL实例(一)

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_datecurrent_timecurrent_timestamp

    变量:局部变量和全局变量
      局部变量:(declare @a int  set @a=1)
        用 declare 申明,用select或者set赋值
      全局变量:(@@IDENTITY......)
        以@@为前缀,每个全局变量都带有不同的意义;

  2、流程控制语句
    顺序流程语句:begin ... end
    判断流程语句:if....elsecase 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
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值