当前位置: 代码迷 >> SQL >> sql随机卡号 随机字母数目字
  详细解决方案

sql随机卡号 随机字母数目字

热度:45   发布时间:2016-05-05 14:55:34.0
sql随机卡号 随机字母数字

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


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

godeclare @cardNum int -- number of carddeclare @needNum int -- the number of card that you need----- inite ---------set @cardNum=0;set @needNum=3000yourNeed:----------------- generate card -------------------declare @cardId varchar(8) -- card iddeclare @i int -- temp----- card Id generatecardId:set @i=0set @cardId=cast((rand()*100000000) as int)set @cardId=right(@cardId+1000000000, 8)if exists(select 1 from dbo.cardInfo where [email protected])goto cardId---- password generatedeclare @j intset @j=0declare @password varchar(6) -- passworddeclare @type int -- type of bit of password(number or a\b\c..)declare @ch chardeclare @charASSIC int -- ASSIC of charset @password=''while(@j<6)begin /*random type*/set @type= cast((rand()*10) as int)if(@type>4) -- use numberbeginset @ch=convert(char,cast((rand()*10) as int))set @[email protected][email protected]--print 'type'+convert(char,@type)[email protected]+' password:[email protected]endelse -- use a b c ...beginset @charASSIC=cast((rand()*27) as int)+96 -- generate a number between 97(a) and 122(z)if(@charASSIC=96) set @[email protected]+1set @ch=char(@charASSIC)set @[email protected][email protected]--print 'type'+convert(char,@type)[email protected]+' password:[email protected]endset @[email protected]+1endinsert into cardInfo(cardId,password) values(@cardId,@password)set @[email protected]+1;if(@cardNum<@needNum)goto yourNeed
?
  相关解决方案