2,我只想在我跟新身份证号时触发“身份证号TO出生日期”这个触发器?同理另一个也一样。 if update(身份证号) begin ... end 3,能否触发器的执行结果不影响其它的行。就是说,我在更新某一个资料时系统不会把其他的行也触发一遍 if update(列名) begin update 表 set 列='xx' where 主键 in (select 主键 from inserted) end
如:create table 表 (a int,b int) go insert 表 values (1,2) go CREATE TRIGGER 名 ON 表 FOR UPDATE AS if update(a) begin select a 更新前a被删除的数据 from deleted select a 更新后a被插入的数据 from inserted end if update(b) begin select a 更新前b被删除的数据 from deleted select a 更新后b被插入的数据 from inserted end go ------------测试: update 表 set a=3 ----------------- update 表 set b=4
CREATE TRIGGER [身份证号TO出生日期] ON dbo.学生 FOR INSERT, UPDATE AS update 学生 set 出生日期 = (case len (身份证号) when 15 then '19'+substring(身份证号,7,6) when 18 then substring(身份证号,7,8) else '19000101' end) 在哪里加 if update(身份证号) ?
2.if update(身份证号)
3.???
if update(身份证号)
begin
...
end
3,能否触发器的执行结果不影响其它的行。就是说,我在更新某一个资料时系统不会把其他的行也触发一遍
if update(列名)
begin
update 表 set 列='xx' where 主键 in (select 主键 from inserted)
end
go
insert 表 values (1,2)
go
CREATE TRIGGER 名 ON 表
FOR UPDATE
AS
if update(a)
begin
select a 更新前a被删除的数据 from deleted
select a 更新后a被插入的数据 from inserted
end
if update(b)
begin
select a 更新前b被删除的数据 from deleted
select a 更新后b被插入的数据 from inserted
end
go
------------测试:
update 表 set a=3
-----------------
update 表 set b=4
FOR INSERT, UPDATE
AS
update 学生
set 出生日期 = (case len (身份证号) when 15 then '19'+substring(身份证号,7,6)
when 18 then substring(身份证号,7,8)
else '19000101' end)
在哪里加
if update(身份证号)
?