zoukankan      html  css  js  c++  java
  • sql server 的 @@rowcount 变量

    @@rowcount

    After each Transact-SQL statement, the server sets the value of this variable to the total number of records affected by it. It can be used to verify the success of selected operations:

         select Make, Model, EqTypeid
         into OldEquipment
         from Equipment
         where EqTypeid = 2
    
         if @@rowcount = 0
            Print "No rows were copied!"
    
    Note 

    Certain statements (like the If statement) will set @@rowcount to 0, and certain statements (like Declare) will not affect it.

    Rowcount_big() is a function introduced in SQL Server 2000. It returns the number of affected records in the form of a bigint number.

    Tip 

    When you try to update an individual record, SQL Server will not report an error if your Where clause specifies a criterion that does not qualify any records. SQL Server will not update anything, and you might, for example, think that the operation was successful. You can use @@rowcount to identify such cases.

    注意在select 和 @@rowcount 之间不要加任何语句,例如

        select top 1 @RatePlanID =  RatePlanID from RatePlan where CarrierID = @CustID and isInBound = @IsInBound
        if (@@rowcount = 0)

    这两句之间如果加一句      select @sameRatePlanID=@RatePlanID

    @@rowcount 会被影响到,导致对select的结果检查不对。

  • 相关阅读:
    随性
    PHP csv文件处理时中文转码
    content...
    macro
    docker Alpine 编译安装node.js的dockerfile文件
    docker hub登录不上一直卡的原因
    java接口与模式(观察者)
    java模式的一点感受
    编码原则之接口隔离
    如何获取web应用的部署路径(多种方式)
  • 原文地址:https://www.cnblogs.com/lthxk-yl/p/3382815.html
Copyright © 2011-2022 走看看