zoukankan      html  css  js  c++  java
  • TSQL

           T---SQL

    SQL: 通用的SQL语言

    T-SQL: 微软对SQL的扩展  (流程控制  存储过程  事物 触发器 错误处理  等)

    注释:-- 单行注释   /**/  多行注释

    数据定义语言(DDL):建立数据库及数据库对象 create

    数据控制语言 (DCL:控制数据库组件的存取许可 权限等命令

    数据操作语言(DML):操作数据库 select update

    流程控制语言 (FCL):控制流程的语句 

    批处理 : GO  SQL批处理是一个或多个 Transact-SQL 语句的集合,由客户端一次性发送到SQL Server实例以完成执行

    定义变量: declare ( 先声明,再赋值 )

    局部变量 标识: @    全局变量:@@

       例: declare @name varchar(10)

            declare @age  int

    变量赋值 :

      set @age=10 只能单个(set @age=10,@name=’张三’ 错 )   

      select @age=10 配合查询 (set @age=10,@name=’张三’ 对 )

    输出方式:

    print: 

    1、以文本形式输出;

    2、输出一个字符串,如果有多个变量或常量要输出,用+连接;

    3、如果类型不一致,用convert函数转换;

    4、输出的结果不易被java等应用程序直接得到

    select: 

    1、以结果集形式输出;

    2、可同时输出多个;

    3、输出的结果可以被java等应用程序直接得到;

    变量

    含义

     

    @@ERROR

        最后一个T-SQL错误的错误号

     

    @@IDENTITY

     

        最后一次插入的标识值

        @@LANGUAGE

         当前使用的语言的名称

     

    @@MAX_CONNECTIONS

     

    可以创建的同时连接的最大数目

        @@ROWCOUNT

        受上一个SQL语句影响的行数

     

        @@SERVERNAME

        本地服务器的名称

     

         @@TRANSCOUNT

        当前连接打开的事务数

     

    @@VERSION

    SQL Server的版本信息

     

    @@ CONNECTION

    连接数

    @@SERVICENAME

    注册表名称

    条件控制语句:

    1) if-else

    if(判断条件)

    begin

                        语句1

                        语句2

    end

    else

    begin

        语句1

                        语句2

    end

            (2) case

    -- 简单格式

    select pcid,

    case PCUse

       when 0 then '空闲'

       when 1 then '忙碌'

                    end as 'pcuse'

                    ,pcnote from pcinfo

    -- 搜索格式

    select pcid,

                    case

       when PCUse = 0 then '空闲'

               when PCUse = 1 then '忙碌'

    end as 'pcuse'

    ,pcnote from PCInfo

     

            (3) while

                             while (循环成立的条件)

    语句xxx

    [break]

    [continue]

     

     

    declare @count int

    while(1=1)

    begin

    select @count = COUNT(*) from cardInfo where cardBalance < 20

    if (@count > 0)

    update cardInfo set cardBalance = cardBalance + 1 where cardBalance < 20

    else

    break

    end

    语句块  begin   开始 end  结束

    查询方式:

    使用比较运算符的子查询、INNOT  IN子查询、EXISTSNOT  EXISTS子查询。子查询若按所处位置划分,可以为子查询在WHERE关键字之后,子查询在FROM关键字之后、子查询在SELECT关键字之后。

    In  查询

       select * from  course where cNO in (select cNO from score where grade is not null)

      连接查询

       select distinct cname,cteacher from course a inner join score b on a.cNo = b.cNO

     

    select a.stuId,a.stumName,b.BID,b.title,c.T_time from student a, book b, borrow c

        where a.stuId=c.stuID and b.BID=c.BID and a.major='计算机

           and c.T_time between '2007-12-15' and '2008-1-8'

      子查询

    select * from student where stuId in(select stuId from borrow where T_time is  not null) 

      

       

  • 相关阅读:
    在IE和Firfox获取keycode
    using global variable in android extends application
    using Broadcast Receivers to listen outgoing call in android note
    help me!virtual keyboard issue
    using iscroll.js and iscroll jquery plugin in android webview to scroll div and ajax load data.
    javascript:jquery.history.js使用方法
    【CSS核心概念】弹性盒子布局
    【Canvas学习笔记】基础篇(二)
    【JS核心概念】数据类型以及判断方法
    【问题记录】ElementUI上传组件使用beforeupload钩子校验失败时的问题处理
  • 原文地址:https://www.cnblogs.com/shuaif/p/3063449.html
Copyright © 2011-2022 走看看