日期:2014-05-18 浏览次数:20596 次
if object_id('aaa') is not null
drop table aaa
go
create table aaa(
Id int identity(1,1),
No int null,
Name varchar(20))
go
create trigger aaa_ins
on aaa
after insert
as
update aaa set No=i.Id
from inserted i
where aaa.Id=i.Id
go
insert into aaa(Name) values('a');
select * from aaa;
------解决方案--------------------
try this,
create table aaa
( Id int identity(1,1),
No int default(isnull(scope_identity(),0)+1),
Name varchar(20)
)
insert into aaa(Name) values('a')
select * from aaa
/*
Id No Name
----------- ----------- --------------------
1 1 a
(1 row(s) affected)
*/