How to check if INSERT went well in stored function?

前端 未结 2 859
青春惊慌失措
青春惊慌失措 2021-01-02 18:14

I\'m creating a stored function which should insert new row to table. In this table is also one unique column.

How can I check if everything goes well and row reall

2条回答
  •  醉梦人生
    2021-01-02 18:47

    Stored Procedures are "all-or-nothing"

    Therefore, if you include an INSERT in the sproc, and that INSERT fails on a duplicate key error, the entire sproc will be rolled back.

    If the sproc executes without error, you can be confident that the INSERT did not have an error. Now, this does not mean the INSERT actually happens just because the sproc completes, just that there were no errors.... for example, if you had some WHERE clause which excludes the INSERT but doesn't throw an error then there may be some ambiguity.

提交回复
热议问题