How to restrict the manipulation time of a table?

3

I would like to know a way to create a trigger in sql-server to restrict the manipulation time of a table between two business hours (8:00 am to 6:00 p.m.).

    
asked by anonymous 18.09.2015 / 04:15

1 answer

0

Yes, it is possible. Below is a code that does this, extracted from Limit user access to a certain time . >

CREATE TRIGGER usrLoginCheck_LogonTrigger
ON ALL SERVER WITH EXECUTE AS 'batchid'
FOR LOGON
AS
BEGIN
declare @EarlyTime datetime,
@LateTime datetime,
@todays_date varchar(25)

set @todays_date = CONVERT(varCHAR(25),GETDATE(),110)
set @EarlyTime = Convert(datetime, @todays_date + ' 07:00:00.000')
set @LateTime = Convert(datetime, @todays_date + ' 23:00:00.000')
if ORIGINAL_LOGIN()= 'batchid'
and getdate() between @EarlyTime and @LateTime 
ROLLBACK;
END
    
18.09.2015 / 12:33