-2
我已经看到了一些类似的问题,像这样的东西出来了:如何在SQL中的(0-15000)之间生成不同的随机100000数字作为金钱类型?
select RAND(CHECKSUM(NEWID()))
但问题是,当我把它换成钱的类型,它失去了一些数字,然后一些行会不会一样了。
以下是我的整个代码,请给我一些建议。
if(exists(select * from sysobjects where name='dump'))
drop table [dump]
--create the table
CREATE table [dump]
(id int ,name varchar(50), price money)
declare @p money=0
set @p= RAND(CHECKSUM(NEWID()))*15000
--set initial value
INSERT INTO dump
values(@i,newID(),@p)
--insert the rows
WHILE(@i<100000)
begin
set @p=RAND(CHECKSUM(NEWID()))*15000
set @i+=1
INSERT INTO dump
values(@i,newID(),@p)
print 'the nth row:'+cast(@i as varchar(15))
end
请 –
感谢您的评论的数据类型打交道时,对不起,总是标记您的DMBS,尤其是我不小心 –
为了澄清 - 你想生成并存储10万'unique'随机数? –