帮忙解决触发器
ALTER TRIGGER INDF on 个人预订
for insert
as
if not exists(select 1 from STUDENT..学生 where 学生号 in (select 学生号 from inserted))
begin
RAISERROR ( '该学生号不存在 ', 16, 1)
ROLLBACK TRANSACTION
end
else
begin
RAISERROR ( '该学生号存在 ', 16, 1)
end
exec insert_indtic '09105095 '
输出总是该学生号不存在
------解决方案--------------------抱歉,更正一下:
把:
if not exists(select 1 from STUDENT..学生 where 学生号 in (select 学生号 from inserted))
改成:
if (select count(a.学生号) from STUDENT..学生 as a
inner join inserted as i on a.学生号 = i.学生号) <= 1
--或者:当表中有自动增量标识列时(假设标识列名称为ID)
if not exists(select 1 from STUDENT..学生 as a
inner join inserted as i on a.学生号 = i.学生号 AND a.ID <> i.ID)