sql随机卡号 随机字母数字

----建立数据库 .....
----建立表 cardInfo cardId varchar(8) password varchar(6)


----直接在sql中跑下面的sql语句就行了。。一次3000个

go
declare @cardNum int -- number of card
declare @needNum int -- the number of card that you need
----- inite ---------
set @cardNum=0;
set @needNum=3000
yourNeed:
----------------- generate card -------------------
declare @cardId varchar(8) -- card id
declare @i int -- temp
----- card Id generate
cardId:
set @i=0
set @cardId=cast((rand()*100000000) as int)
set @cardId=right(@cardId+1000000000, 8)
if exists(select 1 from dbo.cardInfo where cardId=@cardId)
goto cardId
---- password generate
declare @j int
set @j=0
declare @password varchar(6) -- password
declare @type int -- type of bit of password(number or a\b\c..)
declare @ch char
declare @charASSIC int -- ASSIC of char
set @password=''
while(@j<6)
begin 
/*random type*/
set @type= cast((rand()*10) as int)
if(@type>4) -- use number
begin
set @ch=convert(char,cast((rand()*10) as int))
set @password=@password+@ch
--print 'type'+convert(char,@type)+'ch'+@ch+' password:'+@password
end
else -- use a b c ...
begin
set @charASSIC=cast((rand()*27) as int)+96 -- generate a number between 97(a) and 122(z)
if(@charASSIC=96) set @charASSIC=@charASSIC+1
set @ch=char(@charASSIC)
set @password=@password+@ch
--print 'type'+convert(char,@type)+'ch'+@ch+' password:'+@password
end
set @j=@j+1
end
insert into cardInfo(cardId,password) values(@cardId,@password)
set @cardNum=@cardNum+1;
if(@cardNum<@needNum)
goto yourNeed
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值