• begin···end

该语句定义sql代码块,通常在if和while语句中使用

declare @num int ;
set @num=0; while @num<10 begin
  set @num=@num+1;
  print 'hello word' end
  • if···else

条件判断语句,其中else是可选的

if  (select sex from UserBasic where name='张三')=1
print '张三的性别是:男'
else
print '张三的性别是:女'
  •  while、break、continue
declare @num int ;
set @num=0; while @num<10 begin
  set @num=@num+1;
  print 'hello word'
if @num=2
continue
if @num=5
break
end

说明:本例输出5行 hello word

  • goto label(自定义标记)

该语句用来无条件地将语句的执行顺序转到用户定义的lable处

declare @num int;
set @num=0; echo:
print 'hello word'
set @num=@num+1; while @num<10
begin
  goto echo
end
  • return

该语句用来无条件退出一个查询或一个过程

declare @num int ;
set @num=0; while @num<10 begin
  set @num=@num+1;
  print 'hello word'
if @num=5
return
end
  • waitfor delay/time

该语句用来定义某天的一个时刻,执行一个语句块。waitfor delay 'time'表示要等待多长时间,waitfor time 'time'表示要等到哪个时刻执行。

示例:10秒之后输出‘hello word’

waitfor delay '00:00:10'
print 'hello word' --或 print 'hello word' waitfor delay '00:00:10'

示例:12:00钟输出‘hello word’

waitfor time '12:00:00'
print 'hello word' --或 print 'hello word' waitfor time '12:00:00'

SQL Server中的流控制语句介绍的这里。

SQL Server中的流控制语句的更多相关文章

  1. SQL Server中INSERT EXEC语句不能嵌套使用(转载)

    问: I have three stored procedures Sp1, Sp2 and Sp3.The first one (Sp1) will execute the second one ( ...

  2. Sql server中内连接语句

    数据库中学生表和课程表如下: 内连接sql语句: select a.studentName,a.studentAge,b.courseName from student a inner join co ...

  3. SQL server中的T-SQL语句

    首先点击新建查询 如下图所示 创建数据库:create database 数据库名称 使用数据库:use 数据库名称 创建表:create table 表名 ( 代码 ) 输入完成执行时需选中 如果需 ...

  4. sql server 中使用 LIKE 语句 SqlParameter 使用

    原本写的 select * from table where name like  '%@searchStr%' 怎么执行都不对,想想 参数是不能加 引号的 于是改为select * from tab ...

  5. sql server中游标

    参考:http://blog.csdn.net/luminji/article/details/5130004 利用SQL Server游标修改数据库中的数据 SQL Server中的UPDATE语句 ...

  6. SQL Server中【case...end】的用法

    在SQL Server中 case...end 语句,一般有如下两种用法: 1.相当于C#中if...else,例: select CName,头衔=case when CLevel='A1' the ...

  7. SQL Server中查询数据库及表的信息语句

    /* -- 本文件主要是汇总了 Microsoft SQL Server 中有关数据库与表的相关信息查询语句. -- 下面的查询语句中一般给出两种查询方法, -- A方法访问系统表,适应于SQL 20 ...

  8. 为什么SQL语句Where 1=1 and在SQL Server中不影响性能

        最近一个朋友和我探讨关于Where 1=1 and这种形式的语句会不会影响性能.最后结论是不影响.     虽然结论正确,但对问题的认识却远远没有解决问题的根本.实际上在T-SQL语句的书写过 ...

  9. sql server中如何查看执行效率不高的语句

    sql server中,如果想知道有哪些语句是执行效率不高的,应该如何查看呢?下面就将为您介绍sql server中如何查看执行效率不高的语句,供您参考.   在测量功能时,先以下命令清除sql se ...

随机推荐

  1. html实现时间输入框

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. Spring-解决请求中文乱码问题

    解决spring请求中文乱码问题 1.web.xml添加编码拦截器 <filter> <filter-name>CharacterEncoding</filter-nam ...

  3. Maven的Mirror和Repository 的详细讲解

    1 Repository(仓库) 1.1 Maven仓库主要有2种: remote repository:相当于公共的仓库,大家都能访问到,一般可以用URL的形式访问 local repository ...

  4. [JS] jq绑定事件的参数传递

    $(function(){ var obj = {name:"select",param:"2"}; $("#select").click( ...

  5. 理解 atime,ctime,mtime (上)

    理解 atime,ctime,mtime (上) Unix文件系统会为每个文件存储大量时间戳.这意味着您可以使用这些时间戳来查找任意时间访问到的任何文件或目录(读取或写入),更改(文件访问权限更改)或 ...

  6. 利用python 学习数据分析 (学习四)

    内容学习自: Python for Data Analysis, 2nd Edition         就是这本 纯英文学的很累,对不对取决于百度翻译了 前情提要: 各种方法贴: https://w ...

  7. 考试题 T1

    题意分析 就是让你求 \[\sum_{i=1}^{|S|}val[i][gcd(a[i],x)=y]\] 那么接下来就是化简式子 \[\sum_{i=1}^{|S|}val[i][gcd(\frac{ ...

  8. 简单创建一个完整的struts2框架小程序

    要完成一个struts2框架的搭建, 1.首先应该从官网上下载最新的jar包,网络连接:http://struts.apache.org/download.cgi#struts2514.1,选择下载F ...

  9. IDEA + SpringBoot + Java搭建Web项目

    打开IDEA,选择Spring Initializr,默认配置,点击Next  添写GAV.(group.Artifact.Version)  选择Spring Boot版本,这里选2.1.4稳定 ...

  10. POJ – 1200 Crazy Search

    http://poj.org/problem?id=1200 #include<iostream> #include<cstring> using namespace std; ...