create trigger trigger_name
on table_name
for insert,update,delete
as
if (datepart(yy,getdate())%4=0 or datepart(yy,getdate())%100=0)
begin
if (datepart(hh,getdate()) between '0' and '8')
or (datepart(hh,getdate()) between '12' and '14')
or (datepart(hh,getdate()) between '18' and '24')
or (datepart(dw,getdate()) = '7')
or (datepart(dw,getdate()) = '1')
or (datepart(dy,getdate()) between '122' and '128')
or (datepart(dy,getdate()) between '275' and '281')
begin
print'非上班时间,不能插入或修改数据'
rollback transaction
end
end
else if(datepart(yy,getdate())%4!=0 or datepart(yy,getdate())%100!=0)
begin
if (datepart(hh,getdate()) between '0' and '8')
or (datepart(hh,getdate()) between '12' and '14')
or (datepart(hh,getdate()) between '18' and '24')
or (datepart(dw,getdate()) = '7')
or (datepart(dw,getdate()) = '1')
or (datepart(dy,getdate()) between '121' and '127')
or (datepart(dy,getdate()) between '274' and '280')
begin
print'非上班时间,不能插入或修改数据'
rollback transaction
end
end
on table_name
for insert,update,delete
as
if (datepart(yy,getdate())%4=0 or datepart(yy,getdate())%100=0)
begin
if (datepart(hh,getdate()) between '0' and '8')
or (datepart(hh,getdate()) between '12' and '14')
or (datepart(hh,getdate()) between '18' and '24')
or (datepart(dw,getdate()) = '7')
or (datepart(dw,getdate()) = '1')
or (datepart(dy,getdate()) between '122' and '128')
or (datepart(dy,getdate()) between '275' and '281')
begin
print'非上班时间,不能插入或修改数据'
rollback transaction
end
end
else if(datepart(yy,getdate())%4!=0 or datepart(yy,getdate())%100!=0)
begin
if (datepart(hh,getdate()) between '0' and '8')
or (datepart(hh,getdate()) between '12' and '14')
or (datepart(hh,getdate()) between '18' and '24')
or (datepart(dw,getdate()) = '7')
or (datepart(dw,getdate()) = '1')
or (datepart(dy,getdate()) between '121' and '127')
or (datepart(dy,getdate()) between '274' and '280')
begin
print'非上班时间,不能插入或修改数据'
rollback transaction
end
end
drop trigger trigger_name