,歡迎訪問網頁設計愛好者web開發。 1、取出剛剛插入(刪除)的數據select 字段名 from inserted(deleted) 2、對于update實際上是先delete然后再insert所以如果想得到update前后的數據值,應該先從deleted取出,然后從inserted取出; 3、if update(列名)可以判斷更新或插入哪一個字段的值; 4、@@rowcount可以判斷上一行查詢操作得到的列數; 5、給變量賦值用set @zqb = 13; 6、察看是否有符合條件的記錄if exists (select name from sysobjects where name = 'reminder' and type = 'tr'); 7、定義游標,如下: declare c1 cursor for select emp_mgr.emp from emp_mgr, inserted where emp_mgr.emp = inserted.mgr
open c1 fetch next from c1 into @e--從游標中取出數據 while @@fetch_status = 0--判斷是否到最后 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 @e end close c1 deallocate c1--刪除游標引用