Random Şİfre

MS SQL Server veritabanı ve SQL komutlarıyla ilgli sorularınızı sorabilirsiniz. Delphi tarafındaki sorularınızı lütfen Programlama forumunda sorunuz.
Cevapla
hasan
Üye
Mesajlar: 129
Kayıt: 16 Oca 2004 10:01
Konum: Bursa
İletişim:

Random Şİfre

Mesaj gönderen hasan »

merhaba arkadaşlar ;
veritabanınmda 5000 üyem var ve şifre alanları boş , bir SQL Update sorgusu ile tüm alanaara rastgele bir şifre nasıl atarım ?

Kod: Tümünü seç

UPDATE    users
SET  Pass = random() ... 
gibi bişi gerekiyor ?
hasan
Üye
Mesajlar: 129
Kayıt: 16 Oca 2004 10:01
Konum: Bursa
İletişim:

Re: Random Şİfre

Mesaj gönderen hasan »

Aşağıdaki gibi bir SQL buldum ama update satırını nereye sıkıştırcaz ?
[code]declare @pLoopCounter as integer
declare @pMyInt as integer
declare @pMyNewInt as integer
declare @pMyString as varchar(8)
select @pLoopCounter = 1
select @pMyString = ''
while @pLoopCounter < 9
begin
select @pMyInt = cast( rand () * 62 as integer)
select @pMyNewInt = case
when @pMyInt between 0 and 9 Then @pMyInt + 48
when @pMyInt between 10 and 35 then @pMyInt + 55
when @pMyInt >= 36 then @pMyInt + 61

end

select @pMyString = @pMyString + char(@pMyNewInt)
if @pLoopCounter = 8
print @pMyString
select @pLoopCounter = @pLoopCounter + 1
continue
end
GO[/code]
::::::::www.BursaEmlak.com:::::::::
Emlak ve Emlakçının buluşma Noktası
Kullanıcı avatarı
conari
Üye
Mesajlar: 2102
Kayıt: 27 Nis 2006 03:10
Konum: İstanbul & Gebze Karışık

Re: Random Şİfre

Mesaj gönderen conari »

For Best result try following
First, we need to create a View that returns a single random number:

Kod: Tümünü seç

Create view vw_GetRandomNumber
AS
    SELECT  rand() as Num
The view is necessary because normally in a UDF we cannot use the rand() function, because that would make the function non-determistic. We can trick the UDF to accepting a random number by using a View.

Kod: Tümünü seç

CREATE FUNCTION fn_GetRandNumber(@Min int, @Max int)
RETURNS int
AS
 BEGIN
 DECLARE @Return int
    Set @Max = @Max+1
     set @Return =  (@Min) + (select Num from vw_GetRandomNumber) * (@Max-@Min)
return @Return 
 END
Now test with

Kod: Tümünü seç

select dbo.fn_GetRandNumber(1,1) as num
select dbo.fn_GetRandNumber(1,2) as num
select dbo.fn_GetRandNumber(1,15) as num
you will get the result
Cheers!!
Maulik Pandya

Kod: Tümünü seç

update tbl set sifre= dbo.fn_GetRandNumber(1,15)
Bir kelimenin anlamını öğretsen bile yeter..
ResimResim
Cevapla