/*非工作时间不得修改数据*/
create table lecky
(
lid int primary key identity(1000,1),
lname varchar(20),
ldate datetime default getdate()
--默认值为当前时间
)
alter table lecky add constraint ck_lecky
--添加check约束
check
(
(
(
(
(datepart(hour,ldate)>=9) and (datepart(hour,ldate)<12)
--小时数为上午9点至12点
)
or
(
(datepart(hour,ldate)=12) and (datepart(minute,ldate)<=30)
--12点00至12点30
)
or
(
(datepart(hour,ldate)=8) and (datepart(minute,ldate)>=30)
--8:30至8:59
)
)
or
(
(
(datepart(hour,ldate)>=14) and (datepart(hour,ldate)<17)
--同上,为下午的工作时间
)
or
(
(datepart(hour,ldate)=17) and (datepart(minute,ldate)<=30)
)
or
(
(datepart(hour,ldate)=13) and (datepart(minute,ldate)>=30)
)
)
)
and
(
(datepart(weekday,ldate)<>1) and (datepart(weekday,ldate)<>7)
--非周六,日的工作时间
)
and
(
(
(datepart(month,ldate)<>5) and (datepart(month,ldate)<>10)
--除5,10月的工作时间
)
or
(
(datepart(month,ldate)=5) and (datepart(day,ldate)>=8)
--5月8日至31日,即5月除黄金周以外的工作时间
)
or
(
(datepart(month,ldate)=10) and (datepart(day,ldate)>=8)
)
)
)
insert into lecky(lname) values('lecky')
--插入数据测试,测试时双击屏幕右下角的时间,修改系统时间,日期
create table lecky
(
lid int primary key identity(1000,1),
lname varchar(20),
ldate datetime default getdate()
--默认值为当前时间
)
alter table lecky add constraint ck_lecky
--添加check约束
check
(
(
(
(
(datepart(hour,ldate)>=9) and (datepart(hour,ldate)<12)
--小时数为上午9点至12点
)
or
(
(datepart(hour,ldate)=12) and (datepart(minute,ldate)<=30)
--12点00至12点30
)
or
(
(datepart(hour,ldate)=8) and (datepart(minute,ldate)>=30)
--8:30至8:59
)
)
or
(
(
(datepart(hour,ldate)>=14) and (datepart(hour,ldate)<17)
--同上,为下午的工作时间
)
or
(
(datepart(hour,ldate)=17) and (datepart(minute,ldate)<=30)
)
or
(
(datepart(hour,ldate)=13) and (datepart(minute,ldate)>=30)
)
)
)
and
(
(datepart(weekday,ldate)<>1) and (datepart(weekday,ldate)<>7)
--非周六,日的工作时间
)
and
(
(
(datepart(month,ldate)<>5) and (datepart(month,ldate)<>10)
--除5,10月的工作时间
)
or
(
(datepart(month,ldate)=5) and (datepart(day,ldate)>=8)
--5月8日至31日,即5月除黄金周以外的工作时间
)
or
(
(datepart(month,ldate)=10) and (datepart(day,ldate)>=8)
)
)
)
insert into lecky(lname) values('lecky')
--插入数据测试,测试时双击屏幕右下角的时间,修改系统时间,日期