如何检查命令是否在过程中成功执行

时间:2022-03-21 02:05:53

Let's say I have this procedure

假设我有这个程序

ALTER PROCEDURE CallsChange
    @ID int,
    @CS int
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO [ctlCalls] ([InsertDate])
    VALUES (GETDATE())

    UPDATE [ctlOrders]
    SET [DeliverymanID] = NULL,
        [CallId] = (SELECT SCOPE_IDENTITY()),
        [CurrentStatus] = 1
    WHERE ID = @ID 
END

What I want to know is: if there is a SQL Server variable that returns value if after update something has changed in database or not? In other words: if update has been run successfully

我想知道的是:如果有一个SQL Server变量返回值,如果在更新后某些内容在数据库中发生了变化?换句话说:如果已成功运行更新

3 个解决方案

#1


0  

you can use Print statements to check if a command has executed successfuly inside a procedure..

您可以使用Print语句来检查命令是否已在过程中成功执行。

EX:

EX:

create proc usp_test
as
begin

insert into t1
select 2

Print 'Insert completed'

update t
set id=1

print 'update completed'

end

#2


0  

  1. You can use print statement in stored procedure as mentioned in above answer.
  2. 您可以在上面的答案中提到的存储过程中使用print语句。
  3. whenever you execute a stored procedure, the message box will appear how many rows were updated. 3 . Since you are updating with scope identity the table will always be updated with a new value. it it is not updated, you can check in trigger by using INSERTED or DELETED tables
  4. 无论何时执行存储过程,消息框都会显示已更新的行数。 3。由于您使用范围标识进行更新,因此将始终使用新值更新表。它没有更新,您可以使用INSERTED或DELETED表检入触发器

#3


0  

Try this:

尝试这个:

ALTER PROCEDURE CallsChange
    @ID int,
    @CS int,
    @Output varchar(10) = '' OUTPUT
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO [ctlCalls] ([InsertDate])
    VALUES (GETDATE())

    UPDATE [ctlOrders]
    SET [DeliverymanID] = NULL,
        [CallId] = (SELECT SCOPE_IDENTITY()),
        [CurrentStatus] = 1
    WHERE ID = @ID 
   SET @Output = @@ROWCOUNT       
   SELECT  'Updated ' + @Output + ' records'
END

#1


0  

you can use Print statements to check if a command has executed successfuly inside a procedure..

您可以使用Print语句来检查命令是否已在过程中成功执行。

EX:

EX:

create proc usp_test
as
begin

insert into t1
select 2

Print 'Insert completed'

update t
set id=1

print 'update completed'

end

#2


0  

  1. You can use print statement in stored procedure as mentioned in above answer.
  2. 您可以在上面的答案中提到的存储过程中使用print语句。
  3. whenever you execute a stored procedure, the message box will appear how many rows were updated. 3 . Since you are updating with scope identity the table will always be updated with a new value. it it is not updated, you can check in trigger by using INSERTED or DELETED tables
  4. 无论何时执行存储过程,消息框都会显示已更新的行数。 3。由于您使用范围标识进行更新,因此将始终使用新值更新表。它没有更新,您可以使用INSERTED或DELETED表检入触发器

#3


0  

Try this:

尝试这个:

ALTER PROCEDURE CallsChange
    @ID int,
    @CS int,
    @Output varchar(10) = '' OUTPUT
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO [ctlCalls] ([InsertDate])
    VALUES (GETDATE())

    UPDATE [ctlOrders]
    SET [DeliverymanID] = NULL,
        [CallId] = (SELECT SCOPE_IDENTITY()),
        [CurrentStatus] = 1
    WHERE ID = @ID 
   SET @Output = @@ROWCOUNT       
   SELECT  'Updated ' + @Output + ' records'
END