• 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的结果检查不对。

  • 相关阅读:
    动态规划_树形DP
    动态规划_区间DP
    Git
    动态规划_状态机与状态压缩DP
    Mybatis
    3.UIViewController详解
    Flutter boost实现原理简介
    FFmpeg笔记(四)
    Xcode-FFmpeg环境搭建
    FFmpeg(一)
  • 原文地址:https://www.cnblogs.com/lthxk-yl/p/3382815.html
Copyright © 2020-2023  润新知