create table tb(id int identity(1,1),col1 varchar(10),id1 int) go create trigger updateid1 on tb after insert as update a set id1=b.id from tb a inner join inserted b on a.id=b.id go insert into tb(col1) select 'aaa' select * from tb /* id col1 id1 ----------- ---------- ----------- 1 aaa 1(1 行受影响)*/ drop table tb go create table tb(id int identity(1,1),col1 varchar(10),id1 as id) go insert into tb(col1) select 'aaa' select * from tb /* id col1 id1 ----------- ---------- ----------- 1 aaa 1(1 行受影响)*/ drop table tb
计算列create table tb(id int identity(1,1),col1 varchar(10),id1 as id) go insert into tb(col1) select 'aaa' select * from tb
go
create trigger updateid1
on tb
after insert
as
update a set id1=b.id from tb a inner join inserted b on a.id=b.id
go
insert into tb(col1) select 'aaa'
select * from tb
/*
id col1 id1
----------- ---------- -----------
1 aaa 1(1 行受影响)*/
drop table tb
go
create table tb(id int identity(1,1),col1 varchar(10),id1 as id)
go
insert into tb(col1) select 'aaa'
select * from tb
/*
id col1 id1
----------- ---------- -----------
1 aaa 1(1 行受影响)*/
drop table tb
go
insert into tb(col1) select 'aaa'
select * from tb