SQL Scripting, The Museum System

Quick, Hide the Money!

When preparing for training sessions, it is a good idea to elevate your users’ permissions so that they can fully participate in training. However, this can expose users to highly sensitive information – such as valuations – that they would not otherwise have access to. This makes it necessary to hide the money.

Run the following SQL script against your training copy of TMS to replace object values with randomly generated numbers.

DECLARE @ID INT, @MONEY INT

DECLARE ValueObfuscator CURSOR FOR  
SELECT ObjInsuranceID FROM ObjInsurance
OPEN ValueObfuscator   
FETCH NEXT FROM ValueObfuscator INTO @ID   

WHILE @@FETCH_STATUS = 0   
BEGIN   
    SELECT @MONEY = (CAST(CEILING(RAND()*10) AS INT)*(CASE WHEN CAST(CEILING(RAND()*10) AS INT)% 2 = 0 THEN 10000 ELSE 1000 END))
	   +(CAST(CEILING(RAND()*10) AS INT)*(CASE WHEN CAST(CEILING(RAND()*10) AS INT)% 2 = 0 THEN 1000 ELSE 100 END))
    
    UPDATE ObjInsurance SET Value = @MONEY, CurrencyValue = @MONEY, AdjustedValue = @MONEY, RoundedValue = @MONEY, ValueNotes = 'This value has been obfuscated in this database' WHERE ObjInsuranceID = @ID

    FETCH NEXT FROM ValueObfuscator INTO @ID  
END   

CLOSE ValueObfuscator   
DEALLOCATE ValueObfuscator

Trainees can now examine valuation histories, create new valuation records, and use values in loans and insurance policies, but without being exposed to the actual values.

Thanks for taking the time to read my post – I hope you found it helpful.
Leave feedback in the comments below.

If this post save you time, then consider sharing it with your friends and colleagues. If it saved you some money, then please consider buying me a coffee. If you want to know when I publish new content, then subscribe to my feed. Your support encourages me to write more. Thanks!

Quick, Hide the Money!

Leave a Comment