![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 declare @id as nvarchar(36)
2 declare @ctime as datetime
3 declare @starttime datetime, --开始时间
4 @endtime datetime --结束时间
5 select @starttime='1760-08-01 06:00:00',
6 @endtime='2009-11-30 08:00:00'
7
8 set identity_insert tb_TestTable on
9 declare @count int
10 set @count=1
11 while @count<=100
12 begin
13 set @id=replace(newid(),'-','')
14
15 select @ctime= dateadd(
16 minute,
17 convert(int,(rand()*datediff(minute,@starttime,@endtime))),
18 @starttime
19 )
20 insert into funnytbl(id,userName,creattime) values
21 (@count,@id,@ctime)
22 set @count=@count+1
23 end
24 set identity_insert tb_TestTable off
2 declare @ctime as datetime
3 declare @starttime datetime, --开始时间
4 @endtime datetime --结束时间
5 select @starttime='1760-08-01 06:00:00',
6 @endtime='2009-11-30 08:00:00'
7
8 set identity_insert tb_TestTable on
9 declare @count int
10 set @count=1
11 while @count<=100
12 begin
13 set @id=replace(newid(),'-','')
14
15 select @ctime= dateadd(
16 minute,
17 convert(int,(rand()*datediff(minute,@starttime,@endtime))),
18 @starttime
19 )
20 insert into funnytbl(id,userName,creattime) values
21 (@count,@id,@ctime)
22 set @count=@count+1
23 end
24 set identity_insert tb_TestTable off