------解决方案--------------------
go if OBJECT_ID('test') is not null drop table test go create table test( [sid] int identity(1,1) primary key, sno char(8), name char(8), estime datetime ) go if OBJECT_ID('tri_insert') is not null drop trigger tri_insert go create trigger tri_insert on test for insert as declare @sno char(8) begin --这句实现党小于十时用三个零,大于时用两个 --when sid>10,例如00010,那么right(00010,4)=0010 select @sno=ltrim(year(estime))+right('000'+ltrim([sid]),4) from inserted update test set sno=@sno from inserted b where b.[sid]=test.[sid] end
insert into test (name,estime)values('tt','2009-08-30') select *from test