create table td1
(
[ID] int identity(1,1) not null,
num int,
memo1 varchar(10)
)
create table td2
(
[ID] int identity(1,1) not null,
memo2 varchar(10)
)
create trigger tri_td1 on td1
for insert
as
declare @num int
declare @memo int
declare @flag int
set @flag=0
select @num=num,@memo=memo1 from inserted
while @flag<@num
begin
set @memo=@memo+1
insert into td2(memo2) values(right('0000'+cast(@memo as varchar),4))
set @flag=@flag+1
end
go