34,576
社区成员
发帖
与我相关
我的任务
分享
create trigger tr_Test
on Test
for insert,update
as
declare @Msg varchar(2000)
set @Msg=''
if exists (select 1 from inserted i,[FieldValueType] f where f.字段名='ColA'
and case when f.字段类型='float' and isnumeric(i.ColA)<>1 then 1
when f.字段类型='Datetime' and isdate(i.ColA)<>1 then 1
else 0
end=1
)
set @Msg=@Msg+'ColA 类型 错误 '
if exists (select 1 from inserted i,[FieldValueType] f where f.字段名='ColB'
and case when f.字段类型='float' and isnumeric(i.ColB)<>1 then 1
when f.字段类型='Datetime' and isdate(i.ColB)<>1 then 1
else 0
end=1
)
set @Msg=@Msg+'ColB 类型 错误 '
if exists (select 1 from inserted i,[FieldValueType] f where f.字段名='ColC'
and case when f.字段类型='float' and isnumeric(i.ColC)<>1 then 1
when f.字段类型='Datetime' and isdate(i.ColC)<>1 then 1
else 0
end=1
)
set @Msg=@Msg+'ColC 类型 错误 '
if @Msg<>''
begin
RAISERROR (@Msg,16,1)
ROLLBACK TRANSACTION
end