适合于一次往TABLE1插入一条记录:
create trigger tri on table1
for insert
as
begin
declare @a int,@i int
select @a=col1/100 from inserted
set @i=1
while @i<=@a
begin
insert table2(col2) select rand(checksum(newid()))
set @i=@i+1
end
end
create trigger tri on table1
for insert
as
begin
declare @a int,@i int
select @a=col1/100 from inserted
set @i=1
while @i<=@a
begin
insert table2(col2) select rand(checksum(newid()))
set @i=@i+1
end
end
as
udpate COL1
declare @num int
select @num=(sum(isnull(COL1,0))/100) from inserted
while @num<=0
begin
insert table2 (COL2) select cast(rand(checksum(newid()))*5555 as int)
set @num=@num-1
end
create trigger 名 on table1 for insert,update
as
declare @num int
select @num=(sum(isnull(COL1,0))/100) from inserted
while @num<=0
begin
insert table2 (COL2) select cast(rand(checksum(newid()))*5555 as int)
set @num=@num-1
end
create trigger 名 on table1 for insert,update
as
declare @num int,@i int
select @num=(sum(isnull(COL1,0))/100) from inserted
while @num<=0
begin
set @i=cast(rand(checksum(newid()))*666 as int)
while exists(select 1 from table2 where COL2=@i)
set @i=cast(rand(checksum(newid()))*666 as int)
insert table2 (COL2) values (@i)
set @num=@num-1
end
你试试嘛!
0-9:create trigger 名 on table1 for insert,update
as
declare @num int,@i int
select @num=(sum(isnull(COL1,0))/100) from inserted
while @num<=0
begin
set @i=cast(rand(checksum(newid()))*10 as int)
while exists(select 1 from table2 where COL2=@i)
set @i=cast(rand(checksum(newid()))*666 as int)
insert table2 (COL2) values (@i)
set @num=@num-1
end
create trigger 名 on table1 for insert,update
as
declare @num int,@i int
select @num=(sum(isnull(COL1,0))/100) from inserted
while @num<=0
begin
set @i=cast(rand(checksum(newid()))*10 as int)
while exists(select 1 from table2 where COL2=@i)
set @i=cast(rand(checksum(newid()))*10 as int) ---^_^
insert table2 (COL2) values (@i)
set @num=@num-1
end
as
declare @num int,@i int
select @num=(sum(isnull(COL1,0))/100) from inserted
while @num<=0
begin
set @i=cast(rand()*10 as int)
while exists(select 1 from table2 where COL2=@i)
set @i=cast(rand()*10 as int) ---^_^
insert table2 (COL2) values (@i)
set @num=@num-1
end
go
create trigger 名 on table1 for insert,update
as
declare @num int,@i int
select @num=(sum(isnull(COL1,0))/100) from inserted
while @num<=0
begin
set @i=cast(rand()*10 as int)
while exists(select 1 from table2 where COL2=@i)
set @i=cast(rand()*10 as int)
insert table2 (COL2) values (@i)
set @num=@num-1
end
go
insert .......