0
我想更新一個生成隨機「pin」數字的表。這是我想要的,但最後所有的行都獲得相同的數字。我曾嘗試在一段時間內完成它,但它仍然是一樣的。帶有隨機值的SQL Server更新
BEGIN TRAN
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT
---- This will create a random number between 10000 and 99999
SET @Lower = 10000 ---- The lowest random number
SET @Upper = 99999 ---- The highest random number
UPDATE Totals
SET Pin = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
--check for repeated numbers
SELECT
Pin, COUNT(*)
FROM
Totals
GROUP BY
Pin
HAVING
COUNT(*) > 1
--commit
--rollback
感謝您的幫助