我想在触发器里面建立,如果计算机系统时间到某个设的时间,库表就禁止写入.修改时间以后,则可继续写入.
如:
库表a,字段a_1
设定时间为2007-11-20,则到时间库表字段a_1就禁止写入.
修改时间(2007-12-20)以后,则继续可写入,直到(2007-12-20)的时候在禁止写入
那为老大给说明一下,谢谢
如果不用触发器还可以怎么实现?谢谢
如:
库表a,字段a_1
设定时间为2007-11-20,则到时间库表字段a_1就禁止写入.
修改时间(2007-12-20)以后,则继续可写入,直到(2007-12-20)的时候在禁止写入
那为老大给说明一下,谢谢
如果不用触发器还可以怎么实现?谢谢
--在oracle 中相當簡單create trigger 觸發器名
before update of a_1 on t
begin
if to_char(sysdate,'yyyy-mm-dd')<='2007-12-20' then
raise_application_error(-20012,'');
end if; end
instead of insert ,update,delete
as
begin if convert(varchar(10),getdate(),120)<='2007-12-20'
begin print '禁止修改!'
end
end
CREATE TRIGGER 表_Insert
ON 表
Instead Of INSERT
AS
BEGIN
SET NOCOUNT ON;
declare @字段A varchar(100)
set @字段A = (select 字段A from inserted)
if getdate()<='2007-12-20'
print '请在下月20日之后来修改.'
else
INSERT INTO 表 (字段A) VALUES (@字段A)
END
GO
Create trigger trigger_tabname on tabname
for insert
as
begin
if convert(varchar(10),getdate(),120)<='2007-11-20'rollback tranend
楼主可以单独建立一个时间表,里边存储着你想禁止写入的每个时间点,如:
create table a
(id int,
time datetime)
time字段就代表着楼主想禁止写入的各个时间点,楼主可以随时向该表插入那个时间点,用来跟系统时间做比较.create procedure sp
as
begin
declare @a varchar(100)
select top 1 @a=convert(char(10),time,120) from a order by id desc
if @a<>convert(char(10),getdate(),120)
insert into 表 -----
else
print '禁止写入'
end
after insert ,update,delete
as
begin
if convert(varchar(10),getdate(),120)<='2007-12-20'
begin
rollback tran
print('暫不能更新!')
end
else
begin
commit tran
end
end