--如下语句执行一下看看if object_id('test') is not null drop table test go create table Test ( months int, employeeid int, salary int ) insert into Test select 1,1,100 union all select 1,2,200 union all select 1,3, 300 union all select 2,1,200 union all select 2,2,240 union all select 2,3,400 select * from Test go create trigger Tri_Limit on Test for Update as if (select min(months) from inserted)<>(select max(months) from Test) begin print 'Updating Not Allowed' rollback transaction end go select * from test where months=2 and employeeid=2 update test set salary=400 where months=2 and employeeid=2 go select * from test where months=2 and employeeid=2 go select * from test where months=1 and employeeid=2 update test set salary=400 where months=1 and employeeid=2 go select * from test where months=1 and employeeid=2 go drop table Test
go
create table Test
(
months int,
employeeid int,
salary int
)
insert into Test
select 1,1,100 union all
select 1,2,200 union all
select 1,3, 300 union all
select 2,1,200 union all
select 2,2,240 union all
select 2,3,400
select * from Test
go
create trigger Tri_Limit on Test
for Update
as
if (select min(months) from inserted)<>(select max(months) from Test)
begin
print 'Updating Not Allowed'
rollback transaction
end
go
select * from test where months=2 and employeeid=2
update test
set salary=400
where months=2 and employeeid=2
go
select * from test where months=2 and employeeid=2
go
select * from test where months=1 and employeeid=2
update test
set salary=400
where months=1 and employeeid=2
go
select * from test where months=1 and employeeid=2
go
drop table Test
另一个问题是,如果上述"LouisXIV(夜游神)"代码可行,直接拷贝在"视图"运行吗?