sqlserver利用存储过程造随机数据

–dxp_gp_1w造数据存储过程
DROP PROCEDURE add_list;
CREATE PROCEDURE add_list(@num int)
AS
DECLARE @i INT
DECLARE @RandomStr CHAR(1)
DECLARE @RandomStr2 CHAR(1)
DECLARE @RandomStr3 CHAR(5)
DECLARE @Counter INT
DECLARE @Counter2 INT
DECLARE @Counter3 INT
DECLARE @CharPool CHAR(62)
declare @Date_start datetime
declare @Date_end datetime
declare @test_date datetime
declare @test_decimal decimal(18)
declare @test_int INT
declare @test_float float(53)
DECLARE @NumBegin Int=60
–随机数的最小值
DECLARE @NumEnd Int=100
–随机数的最大值
DECLARE @Decimal Int=2
–保留小数点几位
set @Date_start= ‘2018-06-01’
set @Date_end=getdate()
SET @i=1
SET @Counter=0
SET @Counter2=0
SET @Counter3=0
SET @CharPool = ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’
–设置随机序列

WHILE @i<@num
BEGINSET
@test_int=rand()*1000
SET @Counter= cast( floor(rand()*61) as int)
SET @Counter2= cast( floor(rand()*61) as int)
SET @RandomStr = SUBSTRING(@CharPool, @Counter ,1)
SET @RandomStr2 = SUBSTRING(@CharPool, @Counter2 ,1)
SET @RandomStr3 = @RandomStr+@RandomStr2+SUBSTRING(@CharPool, @Counter3 ,2)
select @test_date=dateadd(minute,abs(checksum(newid()))%(datediff(minute,@Date_start,@Date_end)+1),@Date_start)
set @test_decimal=@NumBegin+round((@NumEnd-@NumBegin)*rand(),@Decimal)
set @test_float=@NumBegin+round((@NumEnd-@NumBegin)*rand(),@Decimal)
INSERT INTO [sqlserver_src].[dsp_test_src].[dxp_gp_1w] ([test_bigint], [test_char], [test_date], [test_datetime], [test_decimal], [test_float], [test_int], [test_varchar], [test_text])
VALUES
(@i, @RandomStr, @test_date, @test_date, @test_decimal, @test_float, @test_int,@RandomStr2, @RandomStr3);SET @i=@i+1ENDEXEC add_list @num=10000

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值