日期:2014-05-18 浏览次数:20664 次
use pubs go create table log_jobs (job_id int, newval int,oldval int,date1 datetime) go create trigger kkkk on jobs for update as begin declare @value int select @value=(select count(*) from log_jobs where job_id in (select job_id from deleted)) if @value=0 begin insert into log_jobs select a.job_id,a.min_lvl,b.min_lvl,getdate() from deleted a join inserted b on a.job_id=b.job_id end else begin update log_jobs set newval=b.min_lvl,oldval=a.min_lvl,date1=getdate() from deleted a join inserted b on a.job_id=b.job_id where log_jobs.job_id=a.job_id end end update jobs set min_lvl=180 where job_id=2 select * from log_jobs /* job_id newval oldval date1 ----------- ----------- ----------- ------------------------------------------------------ 1 200 100 2007-11-15 17:10:30.153 2 180 200 2007-11-15 17:11:37.153 (所影响的行数为 2 行) */
------解决方案--------------------
对于多用户的情况,你可以这样实现
当有用户使用这个公共表时你可以先创建一个事物,然后用TABLOCKX把这个表锁定
在这个用户使用完后再用commit来结束事物
这样就OK了