How to check if value is inserted successfully or not?

前端 未结 4 894
栀梦
栀梦 2021-02-01 17:16

I have a procedure where I insert values into my table.

declare @fName varchar(50),@lName varchar(50),@check tinyint
INSERT INTO myTbl(fName,lName) values(@fName         


        
4条回答
  •  轮回少年
    2021-02-01 18:01

    In SQL-Sever you can use OUTPUT clause to check if values are inserted successfully. By following query

     
    declare @fName varchar(50),@lName varchar(50)
    
    INSERT INTO myTbl(fName,lName) OUTPUT inserted.* values(@fName,@lName)  ;
    
     

    IF the values are inserted it will show output of inserted values. You can also store these values into new table.

提交回复
热议问题