Several little common sense (personal finishing) of SQL programming

xiaoxiao2021-03-06  103

1. Remove the data of the data that is just inserted (delete), from INSERTED 2, for Update actually first delete then INSERT, so if you want to get the data value before and after Update, you should take it out from deleted, then remove from Inserted; 3, if update (column name) can determine the value of the update or insert it; is there a matching records iF EXISTS (SELECT name FROM sysobjects WHERE name = 'reminder' AND type = 'TR'); 7, the cursor is defined as follows: DECLARE c1 cURSOR FOR SELECT emp_mgr.emp FROM emp_mgr, inserted WHERE emp_mgr.emp = INSERTED.MGR

OPEN c1FETCH NEXT FROM c1 INTO @ e-- data taken from the cursor WHILE @@ fetch_status = 0-- determines whether the last BEGIN UPDATE emp_mgr SET emp_mgr.NoOfReports = emp_mgr.NoOfReports 1 - Add 1 for newly WHERE emp_mgr.emp @E - Added Employee.

Fetch Next from C1 Into @EndClose C1Deallocate C1 - Delete Cursor Reference

转载请注明原文地址:https://www.9cbs.com/read-97026.html

New Post(0)