Get the App
SLTechnology News&Howtos  ›  Database  › 

How to implement triggers and cursors in sqlserver

Shulou Source: shulou.com Published: 2022-05-31 19:23:25 09月12日 Update

This article shows you how to implement triggers and cursors in sqlserver. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

The code is as follows: Create trigger tri_wk_CSVHead_History on wk_CSVHead_History-declares a tri_wk_CSVHead_History trigger Instead of insert-the insert operation is replaced by performing the following operation as begin declare YB cursor-- declare a cursor for select NoteNO from inserted-- where the NoteNO will match the following open YB declare @ NoteNO varchar (50)-- where the NoteNO will match the above, and define a cursor variable @ NoteNO to manipulate the NoteNo in the insered table. Fetch next from YB into @ NoteNO-- if the NoteNO here matches above, move the cursor while (@ @ fetch_status=0)-- 0 operation succeeded,-1 FETCH statement failed or the row is not in the result set,-2 the extracted row does not exist begin delete from wk_CSVDetail_History where NoteNO=@NoteNO delete from wk_CSVHead_History where NoteNO=@NoteNO fetch next from YB into @ NoteNO-- continue to move the cursor Until @ @ fetch_status is not equal. End close YB-- close the cursor deallocate YB-- release the cursor insert into wk_CSVHead_History select * from inserted end

The above is how to implement triggers and cursors in sqlserver. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Cursors facets triggers content skills knowledge mobility simplicity success succinct code variables that is articles more articles results industries if statements Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology Xiaomi vpn Shulou Tech Info